Forum Moderators: open
There will be 3 dynamicly created forms from a database for example
<form name='form443' action='' method='post'>
code...
</form>
<form name='form442' action='' method='post'>
code...
</form>
<form name='form441' action='' method='post'>
code...
</form>
The problem lies in trying to access these forms within Javascript. The following code has an error in it when i try accessing each form dynamiclly? Any ideas?
<script type='text/javascript'>
function shipping_method($sid){
alert(document.form+$sid.radio_shipping_method+$sid.value);
}
</script>
Thank,
Ryan
i also tried this
alert(document.eval('form'+$sid).eval('radio_shipping_method'+$sid).value);
and it also returend 'undefined'
this is the input varible it is referring to.
<input onclick="shipping_method(<? echo $shipping_row['sid'];?>);" type='radio' name='radio_shipping_method<? echo $shipping_row['sid'];?>' id='radio_shipping_method<? echo $shipping_row['sid'];?>' value='d' />
var f = document.forms['form'+$sid];
if(!f )
{
alert("Unable to find form: 'form" + $sid + "'");
}
if( f )
{
alert("f.elements.length = " + f.elements.length);
var r = f.elements['radio_shipping_method' + $sid ];
if(!r )
{
alert("Unable to find element: 'radio_shipping_method" + $sid + "'");
}
}
<form name='form443' id='form443' action='' method='post'> code... </form>
<form name='form442' id='form442' action='' method='post'> code... </form>
<form name='form441' id='form441' action='' method='post'> code... </form>
<script type='text/javascript'>
function shipping_method (sid) {
var el = document.getElementById('form'+sid);
alert (el.radio_shipping_method.value);
}
</script>