Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

form and dhtml

Status
Not open for further replies.

freeart

Programmer
Joined
Dec 19, 2000
Messages
2
Location
US
I am a web designer and am only good in html but understand dhtml and javascript code. I am trying to do a form questionnaire and halfway through there is a yes/no question. Based on the answer the rest of the form changes.

Is there a way that when someone answers yes, some questions pop up on the same page and when they answer no, different questions show up?

I want to avoid taking them to another page based on that answer, rather I want to keep them on the same page.

 
Yes you can hide and show elements like this in IE:

element.style.visibility="visible"
element.style.visibility="hidden"

in NS like this:

document.layers.element.visibility="show"
document.layers.element.visibility="hide"

it will work in any element in IE, but only absolutely positioned layers in NS prior to version 6. NS6+ can use the same syntax as IE above.
jared@aauser.com
 
yes, you can show or hide layers with the different questions.
 
Hiya, I'm don't know about layers in a page, they probably work far better then this, but it's here if you want to try it, and adjust it to future needs.
Using the onBlur function a user clicks say a radio button between 2 or more choices) and depending upon which he presses, he is sent to a different function, and therefor a different page. Anyhow try it, and let me know how badly it goes wrong! I'm very new to all this, just thought I should contribute something to this forum, as it's helped me so much!

<html>
<body>
<form>

Yes <input name=&quot;yes&quot; type=&quot;radio&quot; value=&quot;yes&quot; onBlur=&quot;goForm()&quot;>

No <input name=&quot;no&quot; type=&quot;radio&quot; value=&quot;no&quot; onBlur=&quot;goForm2()&quot;>
</form>

<script language=VBScript>
Sub goForm()
location.href=&quot;/index.hm&quot;
End Sub
Sub goForm2()
msgbox &quot;you did squat!&quot;
End Sub
</script>
</body>
</html>
 
Nonsense - JavaScript can add elements to droplist boxes, change the wording of questions and the number/content of answers. No need to work with layers. Go to click on programming, on JavaScript and look for the chapter on forms - it's all there.
 
&quot;Really, stay away from layers&quot; --> if you're using netscape<6 you'll be in trouble then !!
 
Antek - please give me an example. Lets say we have a question:

How old are you? <input type=text id=&quot;age&quot; name=&quot;age&quot;>

How do I change the &quot;How old are you?&quot; part, I'm very curious. jared@aauser.com
 
Hello all,

Thank you for your help. I appreciate it. I have got it working in explorer through a different function I found on msdn.com which is something like this...

<div style=&quot;cursor: hand&quot; onclick=&quot;toggle document.all.HideShow);&quot;>
Click Here</div>
<span style=&quot;color: blue&quot; id=HideShow>This will go away<br></span>
This is some text


<script>
function toggle(e) {
if (e.style.display == &quot;none&quot;) {
e.style.display = &quot;&quot;;
} else {
e.style.display = &quot;none&quot;;
}
}
</script>


Now, only to get it working in Netscape. I'm reviewing webmonkey to handle the netscape issue. Thanks for all your help. It was quite great to get this response.

Regards,

rafid@focusg.com
 
to make it work for netscape, it won't be that tough as you already call a function

jsut add the if(document.layers) to detect which browser, then e.style.visibility=&quot;hide&quot; for netscape - i've done it and it works

good luck :-)
 
oops iza - not e.style..visibility you just want e.visibility for NS ;) jared@aauser.com
 
oups !!! thanx jaredn :-)
about the How do I change the &quot;How old are you?&quot; part i suppose it's feasible, but only if &quot;How old are you&quot; is the LABEL of the input field - then it's a property of an object and then it's easy to modify
antek's right, there are other ways than hiding/showing, but hide and show is easier ...
 
not so,labels are not supported in NS ( according to O'reilly's Dynamic HTML - Definitive Reference) jared@aauser.com
 
the only good think i can see in ns is that at least it is a challenge ...
would it be possible to add the label property to the prototype of the textfield object, just like you add a new method (.... as the same time i'm writing this, i'm beginning to think &quot;errrr maybe those prototype redefinitions are allowed only in ie ...&quot;)
 
prototypes work in both browsers, but not on HTML elements - (IE 5+ allows behaviors, which kinda do this, but not &quot;the other browser&quot;) jared@aauser.com
 
ok thanx !!! i'm sorry i didn't have much time to go &amp; read about the prototypes/behaviour that's why i keep asking and asking ... i'll go for sure get some reading and then i come back :-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top