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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Just starting to learn HTML and Javascript

Status
Not open for further replies.

ScrabbleKing

Programmer
Mar 11, 2007
20
0
0
US
I am trying to get the list of options to the cooresponding engine centered below the text box. Then, center the list of engines below that. What should happen is that the options change whenever the engine selection is changed (without having to do an actual search). When a search is executed, it will execute according to the selected option and engine.

Could someone please help with displaying the options and engines properly and the search execution?



<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta name="Content-Script-Type" content="text/javascript">
<meta name="Content-Style-Type" content="text/css">
<title>Search Example</title>
<script language="Javascript" type="text/javascript">


function add_radio_buttons()
{
var google_options = new Array( "Web" , "Images" , "Video" , "News");
var google_actions = new Array( " , " , " , "
var google_variants = new Array(google_options , google_actions);


var yahoo_options = new Array( "Web" , "Images" , "Video" , "Shopping");
var yahoo_actions = new Array( " , " , " , "
var yahoo_variants = new Array(yahoo_options , yahoo_actions);


var metacrawler_options = new Array( "Web" , "Images" , "Audio" , "Video" , "Shopping");
var metacrawler_actions = new Array( " , " , " , " , "
var metacrawler_variants = new Array(metacrawler_options , metacrawler_actions);

var google = new Array("Google" , google_variants);
var yahoo = new Array("Yahoo" , yahoo_variants);
var metacrawler = new Array("Metacrawler" , metacrawler_variants);

var engines = new Array(google , yahoo , metacrawler);// A naming array.

var buttons = new Array();//An array for the three radio buttons of each search engine.


for(var button_index = 0; button_index < 3; button_index++)// Add the type, name, and value attributes.
{
buttons[button_index] = document.createElement('input');// Make a new input element
buttons[button_index].setAttribute('value' , engines[button_index][0].charAt(0).toLowerCase());// Then give it a value.
buttons[button_index].setAttribute('id' , engines[button_index][0].charAt(0).toLowerCase());// Then give it an ID.
buttons[button_index].setAttribute('name' , 'engine');// Then give it a name.
buttons[button_index].setAttribute('type' , 'radio');// Then set the type.
}

var queryform = document.getElementById('qform');// A handy pointer to the form.
var engines_division = queryform.appendChild(document.createElement('div'));// Make a division to stick the radio buttons for each engine into.
engines_division.setAttribute('id' , 'engines');// Then give it an ID.


var i = 0;

while(i < 3)
{// Add the radio buttons to the bottom part of the form.
var current_label = document.createElement('label');// Make a label for each radio button.
current_label.appendChild(buttons);// Then add the button to the label.
current_label.appendChild(document.createTextNode(engines[0] + ' '));// Then add descriptions for the buttons.
engines_division.appendChild(current_label);// Then add the label to the form.
i++;
}

var engine_specific_options_division = queryform.insertBefore(document.createElement('div') , queryform.firstChild);// Add a place to chuck in the engine specific options.
engine_specific_options_division.setAttribute('id' , 'esod');// Then give it an id.

queryform.g.checked = true;// Check the Google option by default.
}

function change_variant()
{

}

</script>
</head>
<body onload="add_radio_buttons()">
<div style="text-align:center">
<form method="get" action=" name="qform" id="qform">
<input name="hl" type="hidden" value="en">
<input maxlength="2048" name="q" size="55" title="Search string" value="">
<input name="btnG" type="submit" value="Search">
</form>
</div>
</body>
</html>
 
MS-IE has a lot of trouble with the NAME attribute on dynamic elements.

See:
YOUR VERY COOL CODE WORKS when you replace the create with the following statement:
Code:
                                    buttons[button_index] = document.createElement('<INPUT NAME=engine></INPUT>');// Make a new input element
 
Thank you, friendlyposter! That helped...well, it did in Microsoft FrontPage. It allows me to choose back and forth between the search engines, but only searches Google (even if either of the others are selected).

However, it does not display the search engines when opening as a webpage. All that displayed was the text box and the search button.

Below is the way I am trying to get the page to look. Just to reiterate with the 'visual', I want the options below the text box to change based upon the search engine selection.

How do I get the appropriate options (based on the engine selection) listed below the text box and then the engines listed below them?


----------------------------------- ----------
| | | Search |
----------------------------------- ----------
o Web o Images o Video o News


o Google
o Yahoo
o Metacrawler
 
You have to attach the new values to then form when the radio button changes.

Here is a starter: (insert after your first line below)
Code:
                queryform.g.checked = true;// Check the Google option by default.
                queryform.g.onclick = seteng0 ;
                queryform.y.onclick = seteng1 ;
                queryform.m.onclick = seteng2 ;

function seteng0()  {
  qform.action=google_actions[0];
}
function seteng1()  {
  qform.action=yahoo_actions[0];
}
function seteng2()  {
  qform.action=metacrawer_actions[0];
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top