Jump to content


 


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.


Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Photo

Basic code


  • Please log in to reply
11 replies to this topic

#1 amyl

amyl

  • Members
  • 77 posts
  • OFFLINE
  •  
  • Local time:12:12 PM

Posted 18 September 2009 - 02:11 PM

I don't know if this is the right forum but I cannot find this code anywhere. I need HTML or Javascript code for
A Field autopopulates with a list of options based on value of another field.

I don't know if you need any info from me.....I was just looking for this basic code or if you can direct me somehwere where I can read how to put this code together. Thanks

BC AdBot (Login to Remove)

 


#2 groovicus

groovicus

  • Security Colleague
  • 9,963 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Centerville, SD
  • Local time:10:12 AM

Posted 18 September 2009 - 02:58 PM

You want some fields to auto-populate depending on the value of another field? Is that what you are asking?

#3 amyl

amyl
  • Topic Starter

  • Members
  • 77 posts
  • OFFLINE
  •  
  • Local time:12:12 PM

Posted 18 September 2009 - 03:07 PM

You want some fields to auto-populate depending on the value of another field? Is that what you are asking?


Yes. I have a list box with options and if option "Example" is selected I would like a different field to auto-populate with the number "4."

#4 amyl

amyl
  • Topic Starter

  • Members
  • 77 posts
  • OFFLINE
  •  
  • Local time:12:12 PM

Posted 21 September 2009 - 10:39 AM

You want some fields to auto-populate depending on the value of another field? Is that what you are asking?


Yes. I have a list box with options and if option "Example" is selected I would like a different field to auto-populate with the number "4."
I am using wform so I can either add HTML code in with the data or save Javascript in a seperate file and specify the file in custom.

I don't know which would be easiest. I have done minimal Javascript but I know enough that I can plug the info I need int othe basic code.



#5 groovicus

groovicus

  • Security Colleague
  • 9,963 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Centerville, SD
  • Local time:10:12 AM

Posted 21 September 2009 - 11:23 AM

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">



<head>

<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />

<title>Untitled 1</title>



	<script type="text/javascript">

	

		function change(){

			var valSelected = document.getElementById("dropDown").value

			document.getElementById("outText").innerHTML = "You have selected " + valSelected;

			document.getElementById("outBox").value = "Selection =  " + valSelected;

		}

	

	</script>

</head>



<body>

	<select name="menu" id="dropDown" onchange="change()">

		<option value="0" selected>(please select:)</option>

		<option value="1">one</option>

		<option value="2">two</option>

		<option value="3">three</option>

	</select>

		<br />

	<div id="outText"></div>

		<br />

	Output:<input type="text" id="outBox" value="This will change"/>

	

	</body>



</html>


#6 amyl

amyl
  • Topic Starter

  • Members
  • 77 posts
  • OFFLINE
  •  
  • Local time:12:12 PM

Posted 21 September 2009 - 02:32 PM

I don't know if it makes any difference....I forgot to inform that I am used Wform to create my form. I have to save the Javascript in a seperate file and put the name of the file in the advanced tab of this Quickform Editor.

Will I still use same code above? (since my list boxes are already created)

#7 groovicus

groovicus

  • Security Colleague
  • 9,963 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Centerville, SD
  • Local time:10:12 AM

Posted 21 September 2009 - 03:40 PM

The code is the same regardless of where you put it, but the IDs are going to be different.

#8 amyl

amyl
  • Topic Starter

  • Members
  • 77 posts
  • OFFLINE
  •  
  • Local time:12:12 PM

Posted 21 September 2009 - 04:19 PM

The code is the same regardless of where you put it, but the IDs are going to be different.


This may be a stupid question....is the ID the same as the name I put for Field Name?

#9 groovicus

groovicus

  • Security Colleague
  • 9,963 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Centerville, SD
  • Local time:10:12 AM

Posted 21 September 2009 - 04:40 PM

No. An id and a name are different; I don't use form builders, so I wouldn't know how to assign an id, or if it is even possible. You would be better off writing the code by hand so that you can see what is really going on. HTML is not very difficult.

I suppose that once you have your form built, you could look at the code it generates (which I assume is going to be HTML anyway), and manually add the id attribute.

#10 amyl

amyl
  • Topic Starter

  • Members
  • 77 posts
  • OFFLINE
  •  
  • Local time:12:12 PM

Posted 22 September 2009 - 07:35 AM

No. An id and a name are different; I don't use form builders, so I wouldn't know how to assign an id, or if it is even possible. You would be better off writing the code by hand so that you can see what is really going on. HTML is not very difficult.

I suppose that once you have your form built, you could look at the code it generates (which I assume is going to be HTML anyway), and manually add the id attribute.



We have to use this form.....it's for my job. The form does come with a JavaScript function File where I can add my code and save as a file...then add the file into this custom field and it reads the code in the background. However, I have used html in the contents within the field of this form instead of putting a code in a file so I was thinking that I could just do the same for Javascript within the text I am using. I wish I could just write my own it would be easier yes!

I will try to figure it out thanks so much for all your help

#11 Guest_WelshSteve_*

Guest_WelshSteve_*

  • Guests
  • OFFLINE
  •  

Posted 07 October 2009 - 10:15 AM

I have been looking for something like this for a while, but a bit more advanced. I am looking to pre-populate a select box based on the option selected in another, but all the data is pulled in from a database using php and mysql.

Is there anything I can use for this?

#12 groovicus

groovicus

  • Security Colleague
  • 9,963 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Centerville, SD

Posted 07 October 2009 - 11:26 AM

Sure. When the option is selected, then read the value from whatever is selected, make an AJAX call to the server to get the data, and then populate the combo box with the data. The Yahoo User Interface Connection Manager library has a simple library for making AJAX calls.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users