Link to home
Start Free TrialLog in
Avatar of dc_law21
dc_law21

asked on

How do I let a user click on an option, and then have this option appear on a form automatically?

I am developing a website using dreamweaver, and have grinded to a hault!
I have a section of the site whereby an orderform is filled in by a user. There is a link to a colour page, and i would like for the user to be able to click on a colour swatch, and have the form updated with the colour name and reference number. Check it out to see what i mean, www.hexagondraw.com.
Avatar of rockmansattic
rockmansattic

this should be done using javascript.

you can put an onclick command on the image and have that image update a piticular field of the order form.

ill get back to you
Rockman



OK
put the script in the head of the page
put the input of the form in your form (you can change the name of the field, BUT also change it in the script
put the onclick action on the images (change the (1) to whatever you need it to be.
Good Luck


<head>
<script language="JavaScript" type="text/javascript">
<!--
function change (newitem){
document.form1.textfield.value=newitem
};
// -->
</script>
</head>


<form name="form1" method="post" action="">
  <input type="text" name="textfield">
</form>

<img src="bullet.gif" width="25" height="25" onclick="change(1)">
Avatar of dc_law21

ASKER

hi rockman

thanks for the reply. Do i put the script into the head of the form page, or the colour page? (sorry, im new to this)
when u say change the 1 to whatever, i take it "change(1)" becomes "change(ral 9010)" etc. What about form.1? does this change to?

Dave
From your question, I assumed that you were using only one page.
Ill have to change a couple of things.

BUT
Yes, change 1 to (ral9010) (that i guess will be the color number?)
yes, also you may have to change form1 for the name of your form

I get back to you about the pages.
I now assume that you have TWO windows open? one with the orderform and the other with the colors?

Rockman
yes, two seperate pages. feel free to have a look if u like, www.hexagondraw.com - click stainless steel, then 'order my rooflight' link to the right

dave
OK
a couple of steps

put this in the head of your ORDERFORM PAGE

<script language="JavaScript" type="text/javascript">
self.name = "orderform"; // names current window as "orderform"
</script>

add target="main" to the links, like this

<img src="bullet.gif" width="25" height="25" onclick="change(1)" target="orderform">

*note, in this senerio, both pages must be open at one time (kind of like a popup, or frames)
how do i create a pop up page? (sorry about this)

Dave
ok, ive got the pop up page working (thanks for that), and ive put the java script into the head of my orderform page. i also put...

<img src="bullet.gif" width="25" height="25" onclick="change(ral9010)" target="orderform">

as a link on the remote page, but when i click it, all i get is page not found.

have i missed something?

dave
I working on it currently.

there are a couple of extra steps I must contend with to ensure proper trasfer of variable.

Rockman
much appreciated rockman,

you clearly know what you are talking about!
i realise im asking a fair bit, so the points are up...
damn, cant. oh well...
OK, got it (FINALLY)


form of the orderform*********************

<input type=button name=choice onClick="window.open('colors.html','popuppage','width=250,height=200,top=100,left=100');" value="Select Color">
<input name="color" type="text" id="color">


colors.html page**********************
<head>
<script language="JavaScript">
function sendcolor(t){

window.opener.document.orderform.color.value = t;
window.close();
}
</script>
</head>


then for each color swatch:
<a href="#" onClick="sendcolor('thiscolor1')"><img src="whatever.gif" height="30" width="30"></a>

Just tested it and it should work

Rockman







ok mate, will try this tommorow (gotta go now) - thanks for the help. Will try it then, and award points accordingly.

anything i can ever help you with (as if!) - just let me know...

Dave
hi rockman,

managed to get the pop up there no problem. However, when i click on the icon for the colour swatch, nothing happens. The pop up stays open, and the form doesn't get filled in.

Does it matter which version of Dreamweaver im using? (Dreamweaver MX) - i just cant crack it. Feels like were so close to!

Dave
ASKER CERTIFIED SOLUTION
Avatar of rockmansattic
rockmansattic

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
thats it, perfect! - one last thing, how would i put a scrol bar on the colour page. Where would the code go etc?

your the man mate!

Dave
on this line

<input type=button name=choice onClick="window.open('colors.html','popuppage','width=250,height=200,top=100,left=100');" value="Select Color">

change to

<input type=button name=choice onClick="window.open('colors.html','popuppage','width=250,height=200,top=100,left=100,scroll=yes');" value="Select Color">

This should work.

Rockman
thanks rockman, all works great now. eternally greatful!