Jump to content

Jscript Question


spectrascope

Recommended Posts

Alright looking for some help here

I am trying to build set of selection boxes, that pass values to a dynamically updating total field.

I can build the combo boxes, but I cannot access the values, much less create a field to add them dynamically on the same page.

so I would like some help doing that if possible, I have already googled this and could not find any help.

 

<form id="gcard" name="gcard" method="post" action="">

<label>Graphics Cards

<select name="Gcards" size="1" id="Gcards">

<option value="300">Ati 4870 HD $300</option>

<option value="200">Ati 4850 HD $250</option>

<option value="480">Nividia GTX280 $480</option>

<option value="260">Nvidia GTX260 $260</option>

</select>

</label>

</form>

Share this post


Link to post
Share on other sites

Jscript is client side, not server side. As such, you'd either have to hard code (not usually recommended), or you'd have to change it on a page refresh (when the form posts), having a conditional at that point.

 

Without seeing the rest of your code, it's hard to draw it up.

Share this post


Link to post
Share on other sites

The page refresh option is kinda what I was looking for a.k.a force refresh each time an option is selected. I have no more code for this idea than above, I really am a noob at this even on the search terms to help find how to implement something like it. So any help is much appreciated. btw thx you clay I did not even know about the refresh option.

Share this post


Link to post
Share on other sites

You'll probably want to use an "onChange" command.

 

You may actually be able to accomplish what you want without a refresh. You'd want something like this:

 

At the top of your page:

<script language="javascript">
  function ChangeValue(form) {
form.gtotal.value = form.gcards.value;}
</script>

 

In your body:

<form id="gcard" name="gcard" method="post" action="">
<label>Graphics Cards
<select name="Gcards" size="1" id="Gcards" onChange="java script:ChangeValue(this.form)">
<option value="300">Ati 4870 HD $300</option>
<option value="200">Ati 4850 HD $250</option>
<option value="480">Nividia GTX280 $480</option>
<option value="260">Nvidia GTX260 $260</option>
</select>
</label>
<input type="text" name="gtotal" value="" readonly>
</form>

 

I think that should accomplish the basic methodology without the need for a refresh. You can then modify it to do what you want (eg. use math in the ChangeValue function...eg. form.gtotal.value = form.gcards.value + form.cpus.value).

 

EDIT: I'm going to sleep now, so if you need anything further, I'll be back on tomorrow i'm sure.

 

Just so you know, if you need to "refresh" the page, you just put the page name in the form action. So say the page is called yourpage.html, then you would have:

action="yourpage.html"

 

That action would only occur if someone hits a submit button and/or image. If you wanted a javascript function to perform when someone submits a form, you'd use an onSubmit, like this:

onSubmit="return FunctionName(passedthruvalue)"

 

Usually a site would post the same page with an onSubmit when they want to validate information, like in a cart. If a site wants to validate information you input, it'll usually post to the same page to perform that validation instead of a new one, because if something is invalid, it can then tell you right there (and thru the wonderful art of coding, even highlight what's wrong), whereas if it went to a different page to perform validation, it would then have to backtrack. Can it be done that way? Sure...but it's not optimal.

 

Anywho, I've probably confused you by now, so I'll shut up. Suffice it to say, if you're not actually having a submittable form, you can pretty much ignore everything in this edit :lol:

 

Gnight :sleep:

Edited by ClayMeow

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...