1 2 3 4 5 6 7 8 9 10 11 | sel = document.frm.select1.selectedIndex; if(sel){ document.frm.select2.remove(sel); //document.frm.select2.selectedIndex =0; }else{ document.frm.select2.options[sel] = new Option('???wat te doen????',2); } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | <head> <title>Javascript</title> <link rel="stylesheet" href="style.css" type="text/css"> <script type="text/javascript"> // setup the main array var setArray = Array("Boek1", "Boek2", "Boek3", "Boek4", "Boek5","Boek6"); // insert the array into the DIV smalltest object function insertArray() { var theText = ""; // set the theText output to an empty string otherwise it would start with null. for (var i=0; i < setArray.length; i++) { // create the array of text to insert theText += setArray[i]; theText += "\n"; // voor de regel tussen de array records } // create the createTextNode var insertText = document.createTextNode(theText); document.getElementById("assortiment").appendChild(insertText); } </script> </head> <body> <div class="loginbalk"> <div class="divcenter"> <div class="loginkolom"> <img src="images/stip.gif" border="0" height="5" width="266"> <span class="blauw">ASSOR</span><span class="zwart">TIMENT</span> <img src="images/stip.gif" border="0" height="5" width="266"> <div class="tekstzwart" id="assortiment"> </div> </div> </div> <input type="submit" value="Bekijk alle boeken" onClick="javascript:insertArray()" /> </div> </body></html> |
Zoiets idd. <input type="image" ... /> is een variant van <input type="submit" ... /> en je hebt dus geen onclick="" nodig.quote:Op donderdag 8 januari 2009 14:26 schreef HuHu het volgende:
Je hebt zelfs het input type "image", zodat je een plaatje als button kunt gebruiken. Dan doe je dus:
[ code verwijderd ]
Zoiets. En als je dan op enter drukt in het text-field submit 'ie hem ook vanzelf.
Hij zet er wel newlines tussen (\n), maar daar doet je browser niks mee in de weergave. <br /> daarentegen...quote:Op woensdag 14 januari 2009 17:17 schreef Apfel. het volgende:
Ik heb een array in javascript. De output hiervan wil ik in een div laten uitkomen. Echter plaatst hij de gehele array achter elkaar erin.
Hij plaatst t als volgt:
boek1boek2boek3 etc
Terwijl ik wil dat het zo komt te staan:
boek1
boek2
boek3
etc
<br /> heb ik ook al geprobeerd. Dan geeft ie gewoon boek1 < br/> boek2 < br/> boek3 < br/> weerquote:Op donderdag 15 januari 2009 14:53 schreef Roy_T het volgende:
[..]
Hij zet er wel newlines tussen (\n), maar daar doet je browser niks mee in de weergave. <br /> daarentegen...
Komt denk ik door dat je createTextNode gebruikt ipv createElement. < en > worden geconverteert naar de html entity's.quote:Op donderdag 15 januari 2009 @ 18:27 schreef Apfel. het volgende:
[..]
<br /> heb ik ook al geprobeerd. Dan geeft ie gewoon boek1 < br/> boek2 < br/> boek3 < br/> weer
1 2 3 | insertText.innerHTML = theText; document.getElementById("assortiment").appendChild(insertText); |
1 |
Ah... ik was even vergeten dat image hetzelfde is als submit.quote:Op woensdag 14 januari 2009 18:33 schreef Light het volgende:
[..]
Zoiets idd. <input type="image" ... /> is een variant van <input type="submit" ... /> en je hebt dus geen onclick="" nodig.
Van de JS libraries vind ik dat persoonlijk de prettigste en cleanste. Welke heeft jouw voorkeur?quote:Op dinsdag 20 januari 2009 18:10 schreef SuperRembo het volgende:
He bah geen jQuery alsjeblieft.
jQuery helpt normale javascript code om zeep en dringt enorm z'n eigen stijl op. Prototypejs heeft dat iets minder, maar daarmee kan je ook geen normale for(.. in ..) loopjes meer maken. Ik heb prototypejs + scriptaculous voor m'n toen/nu site gebruikt, maar voor de volgende versie ben ik wel op zoek naar een nieuwe library. Misschien wordt het YUI.quote:Op dinsdag 20 januari 2009 18:51 schreef Roy_T het volgende:
[..]
Van de JS libraries vind ik dat persoonlijk de prettigste en cleanste. Welke heeft jouw voorkeur?
Als ik Chandler was zou ik iig een library gebruiken, en niet zelf het wiel opnieuw uitvinden.
Daar is juist een library voor: het minder zelf hoeven scripten.quote:Op dinsdag 20 januari 2009 20:17 schreef Chandler het volgende:
Ik ben idd lekker duidelijkmaar dat weten de meeste al.
Ik wil gewoon variabelen uitspugen met mijn php scripting en kunnen gebruiken in javascripting.
daarvoor zou JSON idd erg handig zijn, maar moet ik dan gebruik maken van een externe library? wil liever gewoon de array van php naar js porten zonder al te veel extra scripting
De loopjes met .each() vind juist ik de meest waardeloze feature van jQuery/prototypejs. Zeker met dat gepruts om er toch nog functionaliteit foor break of continue in te bouwenquote:Op dinsdag 20 januari 2009 19:56 schreef Roy_T het volgende:
Ah, dat probleem heb ik helemaal niet met jQuery, maar als ik een library gebruik dan zorg ik ook dat ik 'm overal gebruik. Dus ook voor loops.
Ik ben het met je eens dat het wel bij je moet passen, en dat het alleen werkt als je je manier van proggen erop aanpast. Whatever floats your boatquote:Op dinsdag 20 januari 2009 22:53 schreef SuperRembo het volgende:
De loopjes met .each() vind juist ik de meest waardeloze feature van jQuery/prototypejs. Zeker met dat gepruts om er toch nog functionaliteit foor break of continue in te bouwen![]()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | #### # Function: _jsonEncode # Purpose: To encode a variable into json format # Arguments: $encodeMe: the variable to convert into JSON format # $encodeAs : the name of the variable to save $var1 as. # REQUIRED if $encodeMe is not an array # Usage: # echo _jsonEncode('test','var1');// outputs: {"var1":test"} # echo _jsonEncode(TRUE,'var1'); // outputs: {"var1":1} # echo _jsonEncode(123,'var1'); // outputs: {"var1":123} # echo _jsonEncode(array('orange'=>1,'blue'=>2,'green'=>3)); // outputs: {"orange":1,"blue":2,"green":3} # # Author: Dylan Anderson # License: GPLv3 #### function _jsonEncode($encodeMe,$encodeAs=FALSE){ $output = '{'; if(is_array($encodeMe)){ foreach($encodeMe as $key=>$value){ $output .= '"'.$key.'":'; if(is_array($value)){ $function = __FUNCTION__; $output .= $function($value); } else if(is_numeric($value)) $output .= $value; else $output .= '"'.str_replace('"','\"',$value).'"'; $output .= ','; } $output = rtrim($output,',').'}'; } else if(strlen($encodeAs)){ if(is_numeric($encodeMe)) $output .= '"'.$encodeAs.'":'.$encodeMe.'}'; else if(is_bool($encodeMe)){ $encode_value = ($encodeMe) ? 1 : 0; $output .= '"'.$encodeAs.'":'.$encode_value.'}'; } else if(is_string($encodeMe)) $output .= '"'.$encodeAs.'":'.str_replace('"','\"',$encodeMe).'"}'; } else $output = FALSE; return($output); } ?> |
Als je een PHP array goed encode naar JSON, dan is dat al een JS array. {"elements":[1, 2, 3]} bevat gewoon wat in PHP $elements = array(1, 2, 3) zou zijn.quote:Op woensdag 21 januari 2009 10:24 schreef Chandler het volgende:
maar is er ook los stukje scripting te vinden voor javascript die json kan omzetten naar een array?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 | 1. Copy the coding into the HEAD of your HTML document 2. Add the last code into the BODY of your HTML document --> <!-- STEP ONE: Paste this code into the HEAD of your HTML document --> <HEAD> <style type="text/css"> <!-- @media print { .DONTPrint{ display:none } .DOCheck { display:table} } --> </style> <script type="text/javascript"> <!-- /* This script and many more are available free online at The JavaScript Source :: http://javascript.internet.com Created by: Thony den Braber :: http://www.orangespirits.nl */ function select_row(row, color) { if(row.parentNode.parentNode.style.backgroundColor != color) { row.parentNode.parentNode.style.backgroundColor = color; row.parentNode.parentNode.className = 'DOPrint' } else { row.parentNode.parentNode.style.backgroundColor = ''; row.parentNode.parentNode.className = 'DONTprint' } } function mouseover(row, font_color, checkedcolor) { if(row.style.color != checkedcolor) { row.style.color = font_color; } } function mouseout(row, font_color, checkedcolor) { if(row.style.color != checkedcolor) { row.style.color = font_color; } } // --> </script> </HEAD> <!-- STEP TWO: Copy this code into the BODY of your HTML document --> <BODY> <form> <p> </p> <p>Test kop</p> <p> </p> <p> </p> <p> </p> <table width="103" border="0" cellpadding="0" cellspacing="0"> <tr> <td width="24" align="center"> </td> <td width="79" align="center"><strong>Name</strong></td> </tr> <tr onMouseOver="mouseover(this,'#cc6600','#cc6600');" onMouseOut="mouseout(this,'#000000','#000000')" class='DONTPrint'> <td><input type="checkbox" name="checkbox1" onClick="select_row(this, '#cccccc'); class="DONTPrint""></td> <td>print</td> </tr> <tr onMouseOver="mouseover(this,'#cc6600','#cc6600');" onMouseOut="mouseout(this,'#000000','#000000')" class='DONTPrint'> <td><input type="checkbox" name="checkbox1" onClick="select_row(this, '#cccccc');" class="DONTPrint"></td> <td>niet</td> </tr> <tr onMouseOver="mouseover(this,'#cc6600','#cc6600');" onMouseOut="mouseout(this,'#000000','#000000')" class='DONTPrint'> <td><input type="checkbox" name="checkbox1" onClick="select_row(this, '#cccccc');" class="DONTPrint"></td> <td>print</td> </tr> <tr onMouseOver="mouseover(this,'#cc6600','#cc6600');" onMouseOut="mouseout(this,'#000000','#000000')" class='DONTPrint'> <td><input type="checkbox" name="checkbox1" onClick="select_row(this, '#cccccc');" class="DONTPrint"></td> <td>niet</td> </tr> <tr onMouseOver="mouseover(this,'#cc6600','#cc6600');" onMouseOut="mouseout(this,'#000000','#000000')" class='DONTPrint'> <td><input type="checkbox" name="checkbox1" onClick="select_row(this, '#cccccc');" class="DONTPrint"></td> <td>print</td> </tr> <tr onMouseOver="mouseover(this,'#cc6600','#cc6600');" onMouseOut="mouseout(this,'#000000','#000000')" class='DONTPrint'> <td><input type="checkbox" name="checkbox1" onClick="select_row(this, '#cccccc');" class="DONTPrint"></td> <td>niet</td> </tr> <tr onMouseOver="mouseover(this,'#cc6600','#cc6600');" onMouseOut="mouseout(this,'#000000','#000000')" class='DONTPrint'> <td><input type="checkbox" name="checkbox1" onClick="select_row(this, '#cccccc');" class="DONTPrint"></td> <td>print</td> </tr> </table> <p> </p> <p> </p> </form> <p>test eind</p> |
Forum Opties | |
---|---|
Forumhop: | |
Hop naar: |