...

View Full Version : Repetive call to script



florida
12-04-2006, 02:25 PM
I have about 30 inputs on my page using this in my form page and was wondering how I can call the same script part that is below in a function or a more efficient way of doing it so I dont have to put the <script>...</script> in my form 30 times.



<form action="goto.cfm" method="post">
<input name="other" type="text">
<input name="otherTwo" type="text">
<select name="stateIssue">
<script language="javascript">
for (var i=1; i<101;i++) {
document.write ("<option value='"+i+"'>"+i+"</option>")
}
</script>
</select>
<input name="otherA" type="text">
<input name="otherTwoB" type="text">
<select name="mynameCity">
<script language="javascript">
for (var i=1; i<101;i++) {
document.write ("<option value='"+i+"'>"+i+"</option>")
}
</script>
</select>
<input name="other" type="text">
<input name="otherTwo" type="text">
...
</form>

A1ien51
12-04-2006, 03:13 PM
<script type="text/javascript">
function outputText(){
document.write("<p>hi</p>");
}
</script>

<script type="text/javascript">
outputText();
</script>


You could also do alot of other things, but this is the simpliest

Eric

florida
12-04-2006, 04:15 PM
thanks,

I would still have to put the call to this 30 times in my form page.


<script type="text/javascript">
outputText();
</script>


Is that efficient to have that much <script> and </script> in my form page?

Or is there a more efficient way for me to do this besides putting in this in there instead 30 times which would not have the script tags but would take up more html code:
<option value="0">0</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
...100 times...

A1ien51
12-04-2006, 04:19 PM
More efficient way would be not to use JavaScript at all to build up all of the elements and have a serverside language do it!

If you want to wait until after the page load you can do things like have an array of elements and add values. Meaning you would not have to add it multiple times.

Eric

florida
12-04-2006, 06:44 PM
Thanks for all the info!

I will do this server side instead of client side as you suggested.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum