Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-04-2006, 02:25 PM   PM User | #1
florida
Regular Coder

 
Join Date: Jul 2002
Posts: 362
Thanks: 0
Thanked 0 Times in 0 Posts
florida is an unknown quantity at this point
Repetive call to script

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.

Code:
<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>
florida is offline   Reply With Quote
Old 12-04-2006, 03:13 PM   PM User | #2
A1ien51
Senior Coder

 
A1ien51's Avatar
 
Join Date: Jun 2002
Location: Between DC and Baltimore In a Cave
Posts: 2,717
Thanks: 1
Thanked 94 Times in 88 Posts
A1ien51 will become famous soon enough
Code:
<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
__________________
Tech Author [Ajax In Action, JavaScript: Visual Blueprint]
A1ien51 is offline   Reply With Quote
Old 12-04-2006, 04:15 PM   PM User | #3
florida
Regular Coder

 
Join Date: Jul 2002
Posts: 362
Thanks: 0
Thanked 0 Times in 0 Posts
florida is an unknown quantity at this point
thanks,

I would still have to put the call to this 30 times in my form page.
Code:
<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...
florida is offline   Reply With Quote
Old 12-04-2006, 04:19 PM   PM User | #4
A1ien51
Senior Coder

 
A1ien51's Avatar
 
Join Date: Jun 2002
Location: Between DC and Baltimore In a Cave
Posts: 2,717
Thanks: 1
Thanked 94 Times in 88 Posts
A1ien51 will become famous soon enough
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
__________________
Tech Author [Ajax In Action, JavaScript: Visual Blueprint]
A1ien51 is offline   Reply With Quote
Old 12-04-2006, 06:44 PM   PM User | #5
florida
Regular Coder

 
Join Date: Jul 2002
Posts: 362
Thanks: 0
Thanked 0 Times in 0 Posts
florida is an unknown quantity at this point
Thanks for all the info!

I will do this server side instead of client side as you suggested.
florida is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:57 AM.


Advertisement
Log in to turn off these ads.