Form Name...

  • Thread starter Thread starter 116
  • Start date Start date
1

116

I have aparticular form that every time I enter the form name in, that after
closing the page and re-opening it, the name disappears. I even attempted to
enter it directly into the page code. Still it disappears. Any thoughts? I
believe this to be the issue to why I am having trouble running a proven
jscript on this page.

David
 
Without knowing what could be causing this it's usually easier not to name
forms, rather pass the form to your function. Say you have some script that
runs onsubmit

<form onsubmit="return doForm(this);">
type frontpage here <input type="text" name="a" />
<input type="submit" />
</form>

<script type="text/javascript">
function doForm(f){
if(f.a.value!='frontpage'){alert('type frontpage');return false;}
return true;
}
</script>

Apart from removing issues with form names scripts written this way are also
much easier to re-use. Alternative is to reference by index, eg
document.forms[0] <- 1st form on the page
document.forms[1] <- 2nd form on the page
etc

With either of the above approaches the form doesn't need a name atall.

Cheers,
Jon
http://MyMobileDeal.com
 
Thank you. This was the reason for my script not to work. The
document.forms[#].

David

Jon Spivey said:
Without knowing what could be causing this it's usually easier not to name
forms, rather pass the form to your function. Say you have some script that
runs onsubmit

<form onsubmit="return doForm(this);">
type frontpage here <input type="text" name="a" />
<input type="submit" />
</form>

<script type="text/javascript">
function doForm(f){
if(f.a.value!='frontpage'){alert('type frontpage');return false;}
return true;
}
</script>

Apart from removing issues with form names scripts written this way are also
much easier to re-use. Alternative is to reference by index, eg
document.forms[0] <- 1st form on the page
document.forms[1] <- 2nd form on the page
etc

With either of the above approaches the form doesn't need a name atall.

Cheers,
Jon
http://MyMobileDeal.com

116 said:
I have aparticular form that every time I enter the form name in, that
after
closing the page and re-opening it, the name disappears. I even attempted
to
enter it directly into the page code. Still it disappears. Any thoughts?
I
believe this to be the issue to why I am having trouble running a proven
jscript on this page.

David


.
 
Back
Top