how to change the value in the html tag using jquery
I want to change the param value of the applet tag based on the value from the dropdown. I am new to jquery .can someone tell me how can i do it using jquery .
My applet code :
<applet id="dec开发者_开发问答isiontree" code="com.vaannila.utility.dynamicTreeApplet.class" archive="./appletjars/dynamictree.jar, ./appletjars/prefuse.jar" width ="1000" height="500" >
<param name="dieasenmae" value="Malaria"/>
</applet>
My dropdownc code :
<html:select name="AuthoringForm" property="disease_name" size="1" onchange="javascript:showSelected(this.value)">
<option>Malaria</option>
<option>High Fever</option>
<option>Cholera</option>
</html:select></p>
javascript:
function showSelected(value){
alert("the value given from dropdown is "+value);
$("#decisiontree param[name='dieasenmae']").val(value);
}
just use:
var myNewValue = 'my new value';
$("#decisiontree param[name='dieasenmae']").val( myNewValue );
Live example on JSBin.
Selector explanation:
$("#decisiontree param[name='dieasenmae']")
^ ^ ^ ^
1 2 3 4
- 1 -> inside the ID
decisiontree
- 2 -> find all elements of the type
param
- 3 -> that has the attribute
name
- 4 -> and that attribute value needs to be
dieasenmae
Now that you know how to change the values, that does not mean it will work! as you need to understand and see how the <applet>
will work, as normally, it loads all values on start, and no matter what you do after in the DOM, the Applet can just ignore it... there should have a refresh applet
somewhere, for that, the easiest way is to follow up to this question:
Is there a way to reload/refresh a java applet from within the applet itself?
$('param').attr('value','your-value');
or
$('param').val('your-value');
Make sure to launch it when dom is ready or use document.ready
$(document).ready(function()
{
$("#decisiontree param").val("newValue");
// or
$("#decisiontree param").attr("value","newValue");
});
精彩评论