Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Mar 2005
    Posts
    85
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Question Is this even possible in javascript

    Hi,

    i'm trying to find out if this is possible in javascript: I have a form with default vaules set a combo box. Each value within the combo box sets the recipient e-mail (for the form data) to the corresponding data.

    for example, choosing "webmaster" out of the list sets the e-mail in the cgi script to "webmaster@domain.co.nz", choosing "General info" sets it to "info@domain.co.nz" and so on and so on. (note: i have this part down fine)

    On another web page, I have profiles of different people, and a link under each profile to the form page. What i want is for the default value in that combo box to be set depending on what link was clicked on.

    Is this possible in javascript. If not, what else could it be achieved in. I have next to no experience in JS, so i would not really be able to create this script myself. but if there is some sort of existing script out there, i would love to hear about it!

    please help if you can. thanks a lot in advance

  • #2
    Senior Coder
    Join Date
    Jul 2004
    Location
    New Zealand
    Posts
    1,315
    Thanks
    0
    Thanked 2 Times in 2 Posts
    Yes. Pass the name along in the URL. Use script to extract the name, then match it to a select option. Set that option as selected.
    Forget style. Code to semantics. Seperate style from structure, and structure from behaviour.
    I code to specs, and test only in Firefox (unless stated otherwise).

  • #3
    New Coder
    Join Date
    Mar 2005
    Posts
    85
    Thanks
    3
    Thanked 0 Times in 0 Posts
    thanks so much for the quick reply. much obliged.

    would it be possible for someone to flesh out how to achieve this? I'd have no idea how to write the script for your explanation hemebond

  • #4
    Senior Coder
    Join Date
    Jul 2004
    Location
    New Zealand
    Posts
    1,315
    Thanks
    0
    Thanked 2 Times in 2 Posts
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html lang="en">
    	<head>
    		<title>54705</title>
    	</head>
    	<body>
    		<form action="54705" method="get">
    			<fieldset>
    				<select id="email" name="email">
    					<option value="webmaster@domain.co.nz">Webmaster</option>
    					<option value="info@domain.co.nz">General Info</option>
    				</select>
    			</fieldset>
    		</form>
    
    		<ul>
    			<li><a href="54705?email=webmaster@domain.co.nz">Webmaster</a></li>
    			<li><a href="54705?email=info@domain.co.nz">General Info</a></li>
    		</ul>
    
    		<script type="text/javascript">
    			var email = document.location.search.match(/email=(\w*)/i);
    
    			if(email)
    			{
    				var select = document.getElementById('email');
    				for(var i = 0; i < select.options.length; i++)
    				{
    					if(select.options[i].value.indexOf(email[1]) >= 0)
    					{
    						select.selectedIndex = i;
    						break;
    					}
    				}
    			}
    		</script>
    	</body>
    </html>
    Forget style. Code to semantics. Seperate style from structure, and structure from behaviour.
    I code to specs, and test only in Firefox (unless stated otherwise).

  • #5
    New Coder
    Join Date
    Mar 2005
    Posts
    85
    Thanks
    3
    Thanked 0 Times in 0 Posts
    cool champion. unfortunately i have no bloody idea of what each part of that script is doing. The links that go to my form page are not on the same page as the form, like in your code. I know that your laughing right now, but I seriously dont know what im doing here so please bear with me.

    I have tried to look up on the net on how to fix this up myself, and here's what i've got so far:

    pagewithlinks.html:

    Code:
    <a href="contact.html?name=john" class="blue">Contact John</a>
    contact.html:

    Code:
    <FORM NAME="staff">
    <INPUT TYPE="hidden" NAME="member">
    </FORM>
    
    <SCRIPT LANGUAGE="javascript">
    
    var locate = window.location
    document.staff.member.value = locate
    
    var text = document.staff.member.value
    
    function delineate(str)
    {
    theleft = str.indexOf("=") + 1;
    return(str.substring(theleft));
    }
    document.write(delineate(text));
    
    </SCRIPT>
    obviously, this writes out "john" onto the page. buts that is where I am stuck. I dont want it to document.write....I need it to be stored somewhere within the page so that in the form <select>, I can call upon that stored info to define which option to show by default.

    Plus, if there is no "=" (i.e. if i go straight to contact.html), then it will error, so how would i place some sort of if variable stating that if there is no '=' sign, dont worry?

    if you can help me further with this, it would be fantastic. i dont mind if someone wants to clearly explain hemebonds jscript, or help me out with my script.....i dont care as long as i can get this to work!!

  • #6
    New Coder
    Join Date
    Mar 2005
    Posts
    85
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Code:
    <FORM NAME="staff">
    <INPUT TYPE="hidden" NAME="member">
    </FORM>
    
    <SCRIPT LANGUAGE="javascript">
    
    var locate = window.location
    document.staff.member.value = locate
    
    var text = document.staff.member.value
    
    function delineate(str)
    {
    theleft = str.indexOf("=") + 1;
    return(str.substring(theleft));
    }
    document.write(delineate(text));
    
    </SCRIPT>
    
    <form method="POST" action="cgi-bin\bizmail.cgi" onsubmit="return Contact_Validator(this)" language="JavaScript" name="Contact">
    
    <select name="send_to">
                <option value="1" selected>General info</option><br>
                <option value="4">Webmaster</option><br>
                <option value="2">John Gutsell</option><br>
                <option value="3">Nick Barrett</option><br>
                <option value="5">Mike Walker</option><br>
                <option value="7">Martin Cooksen</option><br>
                <option value="6">David Walker</option>
    </select> 
    		  
    </form>
    
    			<SCRIPT LANGUAGE="javascript">
    			var zork = delineate(text)
    			var john = 'john';
    			var nick = 'nick';
    			var mike = 'mike';
    			var martin = 'martin';
    			var david = 'david';
    			var webmaster = 'webmaster';
    			
    			document.write("variable j =" + john);
    			document.write("variable n =" + nick);
    			
    			if (zork == john){
    				document.Contact.send_to.value = 2;
    			}
    			
    			else if (zork == nick){
    			document.Contact.send_to.value = 3;
    			}
    			else if (zork == mike){
    			document.Contact.send_to.value = 5;
    			}
    			else if (zork == martin){
    			document.Contact.send_to.value = 7;
    			}
    			else if (zork == david){
    			document.Contact.send_to.value = 6;
    			}
    			else if (zork == webmaster){
    			document.Contact.send_to.value = 4;
    			}
    			
    			else {
    			document.Contact.send_to.value = 1;
    			}
    
    			</SCRIPT>
    I have been working on it this afternoon and this is what i have come up to. I think i have answered my own questions through this script, but can someone please tell me if this is valid jscript? it seems to work for me, but if there are any flaws in it, i'd rather it be pointed out now cheers


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •