JavaScript - Get Square And A Select
All,
I have the following code: Code: function createSquare(event) { var x = parseInt(event.clientX); var y = parseInt(event.clientY); var left = x - 50; var top = y - 50; var d = document; var div = event.target.parentNode.lastChild; //alert(div.nodeType) if (div.nodeType != 1) div = d.createElement('div'); div.style.width = "100px"; div.style.height = "100px"; div.style.position = "absolute"; div.style.left = left + "px"; div.style.top = top + "px"; div.style.zIndex = 5; div.style.border = "10pt solid black"; var leftbox = x - 80; alert(x); alert(leftbox); divselect = d.createElement('select'); divselect.style.position = "absolute"; divselect.style.top = top + "px"; divselect.style.left = leftbox + "px"; var sel = d.getElementById('tagged_person'); sel.style.display = 'block' //or block if you have a hidden div var tagged_user = d.tag.tagged_person; tagged_user = tagged_user.value; var picture_id = d.tag.picture_id; picture_id = picture_id.value; divselect.appendChild(sel); event.target.parentNode.appendChild(div); event.target.parentNode.appendChild(divselect); This shows me a square and a select but the select isn't populated with anything. i do have a form later on down the page. The form code is (which I try and pull in the info from the select in the form in the select in the createSqua PHP Code: <form action="" name="tag" method="post"> <input type="hidden" name="picture_id" value="4"> <select name="tagged_person" id="tagged_person"> <?php $qryfav = "Select * from favorites where user_name='creep'"; $resultfav = mysql_query($qryfav); while($resultsetfav = mysql_fetch_array($resultfav)){ echo "<option value=\"$resultsetfav[favorite_user]\">$resultsetfav[favorite_user]</option>"; } ?> </select> </form> Thanks for the help in advance. Similar TutorialsHello wise javascript programers I come to you for help with some programming assignment Im not quite getting the assignment it self is based on the use of the getElementsByClassName() method. Basically I have a 3x3 table with some outer cells that at this point dont do much. there is a loop that iterates through all the inner cells checking for errors. inside the cells, are input boxes. the loop checks to see if the inner cells are empty, contain a non-numeric value, or a zero. if any of this instances is true, a message is displayed explaining the situation. those cells that DON'T have a number will be colored in yellow indicating that numbers should go in there. I got as far as testing all the conditions and generating the appropriate messages, I wrote additional code that supposedly colors the cells that have other than a number in but the code does not execute this is the code if you would like to take a peek at it and help a newbe out. thanks Code: <html> <head> <title>Magic Square</title> <script type="text/javascript"> function checkit() { var j; var inputelement = document.getElementsByClassName("inner"); var colorcells = document.getElementsByClassName("in"); for(j=0;j<inputelement.length;j++) { if(inputelement[j].value=="") { alert(" you must enter a number cells cannot be empty"); for(r=0;r<colorcells.lenght;r++) { colorcells[r].style.backgroundColor="yellow"; return false; } } else if (isNaN(inputelement[j].value)) { alert(" you must enter a number cells cannot be a letter"); for(r=0;r<colorcells.lenght;r++) { colorcells[r].style.backgroundColor="yellow"; return false; } } else if(inputelement[j].value <= 0) { alert(" you must enter a number cells cannot be zero"); for(r=0;r<colorcells.lenght;r++) { colorcells[r].style.backgroundColor="yellow"; return false; } } //end else if } //end first for loop } //end function </script> </head> <body> <table align="center"> <tr><td></td><td class="in"><input type="text" size="1" maxlength="1" class="inner" /></td><td class="in"><input type="text" size="1" maxlength="1" class="inner" /></td><td class="in"><input type="text" size="1" maxlength="1" class="inner" /></td><td><input type="text" size="1" maxlength="1" readonly class="outer" /></td></tr> <tr><td></td><td class="in"><input type="text" size="1" maxlength="1" class="inner" /></td><td class="in"><input type="text" size="1" maxlength="1" class="inner" /></td><td class="in"><input type="text" size="1" maxlength="1" class="inner" /></td><td class><input type="text" size="1" maxlength="1" readonly class="outer" /></td></tr> <tr><td></td><td class="in"><input type="text" size="1" maxlength="1" class="inner" /></td><td class="in"><input type="text" size="1" maxlength="1" class="inner" /></td><td class="in"><input type="text" size="1" maxlength="1" class="inner" /></td><td><input type="text" size="1" maxlength="1" readonly class="outer" /></td></tr> <tr><td></td><td class="in"><input type="text" size="1" maxlength="1" class="inner" /></td><td class="in"><input type="text" size="1" maxlength="1" class="inner" /></td><td class="in"><input type="text" size="1" maxlength="1" class="inner" /></td><td><input type="text" size="1" maxlength="1" readonly class="outer" /></td></tr> <tr><td><input type="text" size="1" maxlength="1" readonly class="outer" /></td><td><input type="text" size="1" maxlength="1" readonly class="outer" /></td><td><input type="text" size="1" maxlength="1" readonly class="outer" /></td><td><input type="text" size="1" maxlength="1" readonly class="outer" /></td><td><input type="text" size="1" maxlength="1" readonly class="outer"/></td></tr> <tr><td colspan="5"><input type="button" value="Check The Magic Square" onclick="checkit()" /></td></tr> <tr><td colspan="5"><input type="button" value="Clear The Magic Square" onclick="clearit()" /></td></tr> </table> </body> </html> What is the [0] for? And even better if you can tell me what they're called, in this context; I want to find a tutorial. Tryit Editor v2.1 PHP Code: var a=document.getElementsByTagName("a")[0]; Thanks! I know very little about javascript, but was wondering if something like this can be done? Would it be possible (with mootools or jquery) to have homepage that will rotate its home page content forwards and backwards based on either triangle or square? ie, you can rotate through 3, 4, etch home pages? Sort of like a slider, but it rotates off a center axis of the triangle or square? Hey, hoping someone can help. As this is my first post and I have a very very very small understanding of Javascript you have permission to mock me! Anyway, here goes... I am using a third party shopping cart system. One of the dropdown menus uses an array as the 'name'. <select name="product[]"> I'm pretty sure it has to stay this way or the cart won't work. I have a function which runs to make sure it can't be left on the first option when submitted, however it won't work with the 'name' containing square brackets! function validate_form_acflgotmt ( ) { valid = true; if ( document.acftshirt.product[].selectedIndex == 0 ) { alert ( "Neigh! Whoa boy, don't forget to choose a t-shirt size!" ); valid = false; } return valid; } If anyone can help please do and I will shed a single tear of joy. Thanks! Jake Hey chaps, hope someone can help with this: I have a PHP form, with a couple of dynamic Select menus, which are populated from two SQL tables: // tbl_main_colour: Code: ID, NAME 1, Red 2, Blue 3, Green // tbl_shade_colour: Code: ID, NAME, FK_MAIN_COLOUR_ID 1, Light Red, 1 2, Dark Red, 1 3, Light Blue, 2 4, Dark Blue, 2 5, Light Green, 3 6, Dark Green, 3 What I'm after is something to filter the second select option, after the first select option has been chosen // Select 1: Code: Red // Select 2: Code: Light Red Dark Red I'm pretty sure this is possible, but not sure how to go about it, any help would be most appreciated. I've been having problems getting my select option to change the options of another select option. I'm not much of a javacsript coder, so I'm at a lost. When I select the first option nothing appears in the second option. here's the javascript code: Code: function createOption(OptionText, OptionValue){ var temp = document.captcha_form("option"); temp.innerHTML = OptionText; temp.value = OptionValue; return temp; } function valChange(){ var firstList = document.getElementById("emailaddress"); var secondList = document.getElementById("subject"); while(secondList.hasChildNodes()) secondList.removeChild(secondList.childNodes[0]); switch(firstList.value){ case "1":{ secondList.appendChild(createOption("Report Site Browsing Issue", Report Site Browsing Issues)); secondList.appendChild(createOption("Report Page Errors", Report Page Errors)); secondList.appendChild(createOption("Other", Other)); break; } case "2":{ secondList.appendChild(createOption("Report Unauthorized Game", Report Unauthorized Game)); secondList.appendChild(createOption("Report Spam", Report Spam)); secondList.appendChild(createOption("Report Harassment", Report Harassment)); secondList.appendChild(createOption("Report Illegal Activities", Report Illegal Activities)); secondList.appendChild(createOption("Request Account Removal", Request Account Removal)); break; } // .... default:{ secondList.appendChild(createOption("Please select from the first list", "")); break; } } } window.onload = valChange; this is the form code Code: <div class="mailto_form"> <form method="POST" id="captcha_form" name="captcha_form" action="../includes/mailform.php"> <div style="padding-bottom: 1em;">Choose Recipient: <select name="emailaddress" id="emailaddress" onchange="valChange();"> <option value=""></option> <option value="1">Webmaster</option> <option value="2">Admin</option> </select> </div> <div style="padding-bottom: 1em;">Subject: <br /><select name="subject" id="subject"> </div> <div style="padding-bottom: 1em;">From: <br /><input type="text" name="email" id="email" value=""> </div> <div style="padding-bottom: 1em;">Enter the text contained in the image into the text box: <br /><img src="../includes/captcha.php" /> <br /><input type="text" name="userpass" value=""> </div> <div style="padding-bottom: 1em;">Message: <br /><textarea name="message" id="message" rows="10" cols="60"><?php echo "</tex" . "tarea>"; ?> </div> <div style="padding-bottom: 1em;"><input name="submit" type="submit" value="Submit"> </div> </form> </div> Link to the page http://www.netgamegurus.com/contact/ Hey Guys When a user changes the select list called "reason_code_master" I need the uodatecodes() function to update all the other select list with the id of "reason_codes" with the same . How can I do this. <select size='1' onchange="updatecodes()" name='reason_code_master'> <option value='' > - SET REASON - </option> <option value='BROKEN' >BROKEN</option> <option value='ENTERED' >ENTERED</option> <option value='SHORT' >SHORT</option> </select> <select size='1' name='reason_codes' id='reason_codes'> <option value='' > - SET REASON - </option> <option value='BROKEN' >BROKEN</option> <option value='ENTERED' >ENTERED</option> <option value='SHORT' >SHORT</option> </select> <select size='1' name='reason_codes' id='reason_codes'> <option value='' > - SET REASON - </option> <option value='BROKEN' >BROKEN</option> <option value='ENTERED' >ENTERED</option> <option value='SHORT' >SHORT</option> </select> <select size='1' name='reason_codes' id='reason_codes'> <option value='' > - SET REASON - </option> <option value='BROKEN' >BROKEN</option> <option value='ENTERED' >ENTERED</option> <option value='SHORT' >SHORT</option> </select> <select size='1' name='reason_codes' id='reason_codes'> <option value='' > - SET REASON - </option> <option value='BROKEN' >BROKEN</option> <option value='ENTERED' >ENTERED</option> <option value='SHORT' >SHORT</option> </select> Hello, I am trying to make a simple code that has a selection list (with the choice fruit or veggie). When the user chooses fruit, the second list displays the options apple, orange, banana. When the user changes their choice to veggie, the second select list then contains carrot, corn, potatoes (and the apple, orange, banana disappear). I need some advice on how to do this Code: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>Untitled</title> </head> <body> <form name = "form1"> <fieldset> <legend>Fruit or Veggie</legend> <select name = "S1"> <option name = "fruit">Fruit </option> <option name = "veggie">Veggie</option> </select> <select name = "S2" </select> </fieldset> </form> <script language="JavaScript" type="text/javascript"> ??? </script> </body> </html> Hi JS Experts, I am working on a class registration system that requires students to register for a main class (101, 102 or 103). The student is supposed to select one main course as well as provide a second choice in case the first is not available. I have two dropdown select fields to capture data 1) Choice -1: 101 / 102 / 103 ( Student needs to select one - Reading the classID from classes table) 2) Choice -2: 101 / 102 / 103 ( If student selects 101 in Choice-1 then the only classes available under Choice-2 should be 102 or 103). How can I accomplish the above? Further to this there are two fields on the form where I would like to auto populate based on what they have selected in Choice-1 and Choice-2. For Example: If a parent selects choice1: 101 the child Choice1 field should autopopulate with 100. If a parent selects Choice2: 201 the child Choice2 field should autopopulate with 200 Any help would be really appreciated. Thanks Vinny Ok so I'm making this form which when a selection is made in one box it will run through the javascript(function getMgmtHours), and update the div(mgmthours). Then another box shows up allowing another selection to be made which runs through the javascript(function getDays) and updates another div(mgmtdate). My problem is that when I use the second box to run through javascript, it overwrites what shows up in the first div (mgmthours) when it should be updating a different div (mgmtdate). Any ideas what I can do to get it update the relevant div and not overwrite the other one? Here is part of the javascript I have in my page head: Code: function getMgmtHours(str) { if (str=="") { document.getElementById("mgmthours").innerHTML=""; return; } if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("mgmthours").innerHTML=xmlhttp.responseText; } } xmlhttp.open("GET","getmgmthours.php?dist="+str,true); xmlhttp.send(); } function getDays(str) { if (str=="") { document.getElementById("mgmtdate").innerHTML=""; return; } if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("mgmtdate").innerHTML=xmlhttp.responseText; } } xmlhttp.open("GET","getdates.php?sunday="+str,true); xmlhttp.send(); } Here is the HTML/PHP portion being used: PHP Code: echo "<p>"; echo "Submit hours:"; echo "<form>"; echo "<select name='district' onchange='getMgmtHours(this.value)'>"; echo "<option value=''>Select a district:</option> <option value='1'>1</option> <option value='3'>3</option> <option value='4'>4</option>"; echo "</select>"; echo "</form>"; echo "</p>" echo "<p>"; echo "<form action='./hours.php' method='post' onSubmit='return checkMgmtHours'>"; echo "Weekending Day: "; echo "<select name='weekending' onchange='getDays(this.value)'>"; echo "<option value=''>Choose a Date:</option>"; while ($week < 32) { $nextsunday = strtotime("next Sunday"); if ($week > 0) { $timestamp = strtotime("-" . $week . " week", $nextsunday); } else { $timestamp = $nextsunday;} $weekending = date('M. d, Y', $timestamp); echo "<option value='" . $weekending . "'>" . $weekending . "</option>"; $week = $week + 1; } echo "</select>"; echo "<div id='mgmtdate' />"; echo "<div id='mgmthours' />"; echo "</p>"; Edit: Also, after getMgmtHours() runs, I can still use both getDays and getMgmtHours, howeer once I used getDays, I am no longer able to use getMgmtHours w/o refreshing the page. I have a select box that has ~7000 options, that based on a different dropdown select & input field, gets filtered to 0 - 300 entries. I have another select dropdown that has 13000+ options in total for all the ~7000 entries, but each entry may have 1 to 5 options of these 13000. Is there a way to change the options of the last select dropdown based on what the user chooses in the filtered select box? Currently the idea I'm having is to have the browser load all 13000+ items and filter out the ones that don't apply to the currently selected item, but I'm not sure what kind of lag the user would experience while the browser loads & filters through all these items. Any help would be appreciated. Thanks. I've got some directory list boxes on the site I'm working on. I made them big and fixed rather than drop-down so they're easier to use in this context. But I had to enable the "multiple" attribute to make that work. The site has no provision for multiple selections so it's a tad annoying when the search function selects more than one name in the list. It doesn't really affect the site's operation but it could be confusing to some people. Is there a way to make the listbox show multiple selections without allowing multiple selections? Thanks for any help. <select onchange="display.apply(this, this.value.split(','))" multiple="multiple" id="People" name="People" style="border-style: none; height:244px; width:220px; margin-bottom: 15px;"> <option>Loading</option> </select> Hi All, First time user of this forum and need some help please. I have a webpage where I am displaying checkboxes next to rows. I would like to have one checkbox which will select everything. I have written this code but it does'nt seem to work. Can someone advice as to whats wrong here. The HTML code for checkAll checkbox is: Code: <thead> <tr> <th>Select All <input type='checkbox' name='checkall' onclick='checkedAll(frm1);'> </th> The HTML code for each checbox is : Code: <form id="frm1" /> <tbody> <?php foreach ($consignment_array as $ct_idx => $consignment) { $status = $consignment->getStatus(); $id= $consignment->getId(); ?> <tr class="<?php echo "cls" . $status; ?>"> <td id="c"> <input type=checkbox id= "1" name="deleteConsignments" onclick="row_color(this)" value= <?php echo $consignment->getId(); ?> /> </td> The javascript is : Code: function checkedAll (frm1) { alert("in check all"); var aa= document.getElementById('frm1'); if (checked == false) { checked = true } else { checked = false } for (var i =0; i < aa.elements.length; i++) { aa.elements[i].checked = checked; } } The problem is that its not even going into the Javacript because I dont get the alert. Appreciate the help guys. Thanks. Code: <select name="selectme" onChange=""> <option value="layer1name">1</option> <option value="layer2name">2</option> <option value="layer3name">3</option> </select> how can you make a onclick for this to work. So if you cliked the seconde one it would change somthing(i dont care what). hello, how can I set a selected item of a drop down menu (select in html) knowing its value and given a variable "dropdown" that points to the select ? Thanks Hi, I have a select option inside a span, how do i get the select id. Code: <span id="getSelect"> <select id="myselect" name="mySelect" option../> </span> document.getElementById("getSelect").innerHTML; this will give me the whole select object...now how do i get the select id from that. Thanks Hi I have a form. In this form i have a pop down menu with 1,2,3,4,5 numbers in it. And after that i have 8 more form fields. what i want is when user select any number from pop down menu then these 8 fields should appear. for example when user select 2 from pop down menu then then these set of fields should appear twice i mean 8+8=16. and so on. my code is here Code: <!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 http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <form id="form1" name="form1" method="post" action=""> <p> <select name="jumpMenu" id="jumpMenu"> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> </select> </p> <p> Type : <select name="jumpMenu2" id="jumpMenu2" onchange="MM_jumpMenu('parent',this,0)"> <option value="Delux">Delux</option> <option value="king">king</option> <option value="exe">exe</option> </select> </p> <p> <label>Number: <input name="textfield" type="text" id="textfield" size="5" /> </label> </p> <p> <label>Name: <input type="text" name="textfield2" id="textfield2" /> </label> </p> <p>Date Arr: <label> <input type="text" name="textfield3" id="textfield3" /> </label> </p> <p>Dep Date: <label> <input type="text" name="textfield4" id="textfield4" /> </label> </p> <p> <label> <input type="checkbox" name="checkbox" id="checkbox" /> Extra</label> </p> <p> <label> <input type="checkbox" name="checkbox2" id="checkbox2" /> Park</label> </p> <p>Remarks: <label> <textarea name="textarea" id="textarea" cols="45" rows="5"></textarea> </label> </p> </form> </body> </html> how this can be done in js Hi all, I am a newbie to JS. So please extend your help suggesstion to solve this problem I have. I have 2 select boxes. Data in one select box is corresponding to the data in the other select box. When the user comes in and selects example the 3rd element from the first or second select box the correspoinding 3rd element from the other select box should be selected. Please help with the solution.Thanks in advance I am trying but I can't figure it out, let say you select something on your select values, after selecting that value, how can you dynamically put that value on an input box?
Hy ! I have this form: PHP Code: <form name = "myform" method = "POST" action = "proba1.php"> Name:<br /> <input type = "text" name = "name" size = "30" onBlur = "namecheck()" /><br /> Username:<br /> <input type = "text" name = "username" size = "30" onBlur = "usercheck()" /><br /> Password:<br /> <input type = "password" name = "password" size = "30" /><br /> Repeat password:<br /> <input type = "password" name = "password2" size = "30" onBlur = "passcheck()"/><br /> Email:<br /> <input type = "text" name = "email" size = "30" onBlur = "mailcheck()" /><br /><br /> <input type = "reset" name = "reset" value = "Reset" /> <input type = "submit" name = "submit" value = "Submit" /> </form> and a Js file to check it: PHP Code: function namecheck() { var name = document.myform.name.value; if(name.indexOf(" ") < 0) { document.myform.name.focus(); document.myform.name.select(); alert("Pleaase enter your full name!") return false; } return true; } function usercheck() { var username = document.myform.username.value; if(username.length < 6) { alert("Username must be at least 6 chars!"); document.myform.name.focus(); document.myform.name.select(); return false; } return true; } function passcheck() { var password = document.myform.password.value; var password2 = document.myform.password2.value; if(password != password2) { alert("The two passwords not identical!") } } function mailcheck() { var mail = document.myform.email.value; var diff = mail.lastIndexOf(".") - mail.indexOf("@"); var diff2 = mail.length - mail.lastIndexOf("."); if(mail.indexOf("@") < 0 || mail.indexOf(".") < 0 || diff < 2 || diff2 > 3) { alert("Not a valid email adress!") } } So when a value is not proper,there should be an alert message,then select and focus on the field.But only the alert works.I can set the select and the focus to any other field from the current one ,but not to the current.(For instance:if the name is not good:document.myform.username.select() works,but :document.myform.name.select() not.) Can somebody help me? |