If/then with forms quandry

Hey there-new to this board,
I am fairly new to JS, I hope someone could help me with this supposedly ‘simple’ task!

The problem lies with this snippet of code:
(if you want to see the entire html page, you can view it at:
http://www.perfectlygrand.com/mod1_quiz1b.html)

<input type="button" name="Button" value="Submit" onClick="if (value == "b") {MM_openBrWindow('1right.html','','width=230,height=150')) else {MM_openBrWindow ('1wrong.html','','width=230,height=150')}">

What I am trying to achieve is a button that, when pressed will read which radio button the person has pressed and then will launch a relevant pop-up window depending on whether they pressed the ‘b’ radio button or if they’ve pressed something other than b(which will then popup with a different window).

Hey poe,

I didn’t fix your problem (although I know how), but instead I whipped up a quick .html file you can check out.

I commented everything in the code so it could help you understand what I did.

I hope it helps. If you have any questions, just ask.

Thanks LIB, I know my Fiance will appreciate that. :slight_smile:

yes Poe is Laurie. :slight_smile: (well, actually he’s our dog, but you know what I mean. :slight_smile: )

oh… :beam:

She is welcome. If she needs any more help she can just ask.

Oh yeah, I snooped in her source to see what else she was doing and…

she should use

<B></B>

instead of

<strong></strong>

Strong is a bit outdated, that is older HTML :slight_smile:

(the B stands for bold, so its easy to remember that way too)

hmm… looks about like what she was discribing. Should help anyway.

Question though… as this works, all the answers are stored on the html page that contains the questions. Is there an easy way, without using CGI to contain those answers in a separate file, elsewhere on the server?

Laurie didn’t ask, I’m just interested in that answer

She could copy and paste the content between the script tags (she can delete the script tags), put it in an external .js file (can save one of these in notepad, just save as “All Files” and put the extension .js at the end). And then insert the code into the page like this…

<script src="script.js" type="text/javascript"></script>

She can probably cleverly disguise the name of the .js file so people think it doesn’t have to do with the quiz thing.

When the source is viewed, the script right above will show, not the actual script that she has in the .js file.

[edit]Hey david, did you ever check out that script I sent you for dynamic pop-ups in Flash or something like that. It was a while ago, but I just saw the file on my comp and it reminded me of it [/edit]

I probebly have not. I’ve been having difficulty getting on Flash and doing any work with it for quite some time now. Send it again, I’ll look at it, I promise. :slight_smile: (ps MX still isn’t working yet, so I need it in 5.0 version if possible)

Hrmm, I believe this is the file. I think I had a friend to it for me on Flash 5, so you could open it. I don’t have the .zip file, so I hope I didn’t open it and save it again as Flash MX… :-\

I remember you wanted the page to load from your variable name or something along those lines.

Lost in Beta,

=) =) =) =)

Thank you for your reply!

The code works like a charm,so happy-still trying to get my head around what kind of commands to use where in javascript.

Thanx for the strong tag tip-
I’m sure you’ll see me around here plenty!
~Laurie

Hey there!

its me again,
I realized that in picking an answer to the question,you should only be able to pick one radio button. I know that when you keep the name the same throughout the buttons it allows you to do this, but since I need the names to be different on every one,(for the if/then statement to work) I can’t do this.

There must be a way!
I think I am a lil bit confused as to what the difference is between a name and a value is.
~Laurie

'DOH! My greatest apologies.

I checked the results directly from the name, but completely forgot to check the id (or add the id for that matter). This is actually my first time doing this so I was bound to make a mistake…lol.

Ok, I have attached a new .zip file. This one should work with only checking one item.

Please note that I added an id=“x” (x = some letter) into each of the radio button form elements. This gives each button a specified id, while keeping the same name.

Oh yeah, as for names and values…

Name = Assigns an identifier to the element.
Value = Preassigns a value for the input element for submission to the server. Basically, the name given under value is what the server reads after you submit the form(or at least I believe that is how it goes)

I hope this helps :slight_smile:

WAIT WAIT WAIT… Don’t download that last one.

LOL, ok, so the change I made in this one is probably unnoticeable, but I uploaded it anyway.

Can you spot the difference (that is, if you downloaded the other file)? They both work either way, the second one is just slightly… optimized (???)…lol… if you could call it that.

Hi Lostinbeta-
I have not had the opportunity to download 2.0 of formtest, but have a question. In netscape communicator 4.7 the pop-ups are not working, works in 4.0 -bazaar- but if I go into the built in javascript debugger it says the first line of the javascript code does not have any properties. Do you know what this could be? The only reason I’m asking is because the clients target browser is <g> 4.7

Thanks for your help
~Laurie

Hmmm, well it works in Netscape 7, that is the only version I can test it on here… so my apologies.

I am not quite sure how to fix this problem as I do not have Netscape 4.7 to test it on.

I did come up with this though… (check attachment).

What I did here was saved the first line into a variable, and then executed that variable in the if statement. Hopefully that works :-\

Thanx for the alt. code,
unfortunately netscape 4.7 is not accepting that either-javascript error. Could it be that that version did not accept a certain kind of command?

Is there any other way to get the same results while changing the code?
I’m working on this myself, but with the limited knowledge I have right now of JS it proves to be difficult.

~L

ooh!ooh!

I found out why its not working. I looked in my dreamweaver reference guide and is says that Netscape Navigator does not support the ‘id’ tag. I tried the html document that we had before we changed it to ‘id’ and it works!!!

At least I’ve found out the problem, -now I just don’t know the solution!
I’m so psyched to have been able to partially solve the problem.:stuck_out_tongue:
~L

Oh boy… without the id… I don’t think this is possible.

But never say never eh? I will give this another shot :slight_smile:

:::sigh:::

I have tried and tried and tried and tried and tried some more, but I can’t find a way to return results based on the value instead of the ID of an item :frowning:

Since the ID is the actual locator of the object, the script you current has says “if this location is checked, then do this”, but without a locator, it can’t check what is checked :-\

I didn’t even know people still used that version of Netscape :-\

HA!
You would be SURPRISED at what ancient browsers corporate america is using these days
:stuck_out_tongue:
Anyway, I decided to go about it in a different way(god knows what kinds of problems I will run into with this one):


<form name="form">
                <input type="radio" name="one" value="a">
                <font size="2" face="Arial, Helvetica, sans-serif">a. 5 years 
                in prison and/or a fine of up to $125,000 </font></p>
              <p> 
                <input type="radio" name="one" value="b">
                <font size="2" face="Arial, Helvetica, sans-serif">b. 10 years 
                in prison and/or a fine of up to $250,000 </font> </p>
              <p> 
                <input type="radio" name="one" value="c">
                <font size="2" face="Arial, Helvetica, sans-serif">c. 20 years 
                in prison and/or a fine of up to $500,000</font></p>
              <p> 
                <input type="radio" name="one" value="d">
                <font size="2" face="Arial, Helvetica, sans-serif">d. None of 
                the above</font></p>
              <p><font size="2" face="Arial, Helvetica, sans-serif"> 
              <input type="Reset" name="Reset" value="Reset">
			  <input type="Button" name="Button" value="Submit" 
			  onClick="if (this.form.b.checked){ 
_____MM_openBrWindow('1right.html','','width=230,height=150'); 
__} 
__else { 
_____MM_openBrWindow ('1wrong.html','','width=230,height=150'); 
__} 
}">
                              </font></p></form>

Its not working, do I need to refer to:

 
(this.form.b.checked)

in the header before I call out to it??

~L

Well the main problem with that is that you are defining the whole if statement on the onClick.

You need to define the if statement in a function as I did in my previous examples.

Another problem here are the __ you have before your actions in your if statement.

And another is that you are using values. And from what I tried, you can’t determine what is checked by value, but instead… ID.

:-\ :frowning: