Jump to content

kigogu

Members
  • Posts

    39
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

kigogu's Achievements

Member

Member (2/5)

0

Reputation

  1. this would be something that works <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title></title> <link rel="stylesheet" type="text/css" href="style.css"></link> <script type="text/javascript"> var count = true; document.getElementsByAttribute=function(attrN,attrV,multi){ attrV=attrV.replace(/\|/g,'\\|').replace(/\[/g,'\\[').replace(/\(/g,'\\(').replace(/\+/g,'\\+').replace(/\./g,'\\.').replace(/\*/g,'\\*').replace(/\?/g,'\\?').replace(/\//g,'\\/'); var multi=typeof multi!='undefined'? multi: false, cIterate=typeof document.all!='undefined'? document.all: document.getElementsByTagName('*'), aResponse=[], re=new RegExp(multi? '\\b'+attrV+'\\b': '^'+attrV+'$'), i=0, elm; while((elm=cIterate.item(i++))){ if(re.test(elm.getAttribute(attrN)||'')) aResponse[aResponse.length]=elm; } return aResponse; } function edit() { if(count) { // Get all input elements into an object var inputs = document.getElementsByTagName('input'); // Loop through inputs for( var i=0; i<inputs.length; i++ ) { // create new element to insert before var button = document.createElement('button'); // Set the inner HTML of the button to 'edit' button.innerHTML = 'Edit'; // Set onClick action button.setAttribute('onclick', "doAlert('"+ inputs[i].id +"')"); var parents = inputs[i].parentNode.id; document.body.insertBefore(button, inputs[i]); } var inputs = document.getElementsByTagName('textarea'); // Loop through inputs for( var i=0; i<inputs.length; i++ ) { // create new element to insert before var button = document.createElement('button'); // Set the inner HTML of the button to 'edit' button.innerHTML = 'Edit'; // Set onClick action button.setAttribute('onclick', "doAlert('"+ inputs[i].id +"')"); // Append the button before the current input document.body.insertBefore(button, inputs[i]); } var inputs = document.getElementsByTagName('img'); // Loop through inputs for( var i=0; i<inputs.length; i++ ) { // create new element to insert before var button = document.createElement('button'); // Set the inner HTML of the button to 'edit' button.innerHTML = 'Edit'; // Set onClick action button.setAttribute('onclick', "doAlert('"+ inputs[i].id +"')"); // Append the button before the current input document.body.insertBefore(button, inputs[i]); } var inputs = document.getElementsByTagName('label'); // Loop through inputs for( var i=0; i<inputs.length; i++ ) { // create new element to insert before var button = document.createElement('button'); // Set the inner HTML of the button to 'edit' button.innerHTML = 'Edit'; // Set onClick action button.setAttribute('onclick', "doAlert('"+ inputs[i].id +"')"); // Append the button before the current input document.body.insertBefore(button, inputs[i]); } count = false; } } function doAlert(elementID) { var tag = document.getElementById(elementID); if(tag.tagName == 'LABEL') { window.open('editor.php?value='+ document.getElementById(elementID).innerHTML + '&id=' + elementID + '&tag=' + tag.tagName, 'popup title', 'toolbar=0, scrollbars=0, location=0, statusbar=0, menubar=0, resizable=0, width=400, height=300'); } else { window.open('editor.php?value=' + document.getElementById(elementID).value + "&id=" + elementID + "&tag=" + tag.tagName, "popup title", "toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=400,height=300"); } } </script> </head> <body> <button onclick="edit()">Edit</button><br /> <input type="radio" class="radio1" /> <textarea id="textarea">Rawer</textarea> <img src="google.com" id="img1" /> <label id="phone">rawrrr</label> </body> </html> but once you get to placing, say the radio button, in a div tag then that is where everything breaks
  2. Seems to be a loss of scope issue. Your JS is likely looking for a child of body and not body>div So i assume the document.body.insertBefore() has something to do with it xP would i have to keep all of the parents of the element so like document.body.div1.div2.insertBefore() ? if so, is there a way to get all the parents of the given input? or would there be a quicker way of going about this? lol completely new to javascript so i'm trying to learn as i go
  3. Alright so I kind of deduced that its the html that is messing it all up, when i delete everything except the content then it will work. when i encompass the data in a div tag is when the javascript doesn't work. Any thoughts on why the javascript doesn't work due to div tags? Works <html> <body> <input type='text' /> </body> </html> Doesn't work: <html> <body> <div> <input type='text' /> </div> </body> </html>
  4. I'm not really sure what to put as the subject, but anyways I have this javascript that runs when i click an edit button, just calls the edit() function and what I want it to do is place an edit button next to every element that is an input, textarea, img, and label. the script itself works fine, but the html that i'm having it place the edit buttons next to is being displayed by a php function. So what i think is the problem is that the javascript wont read the html that is being displayed by the php function? since it reads the html first and finds that nothing matches or something? if this is the problem how might i go about to fix it? Here is the javascript: <script type="text/javascript"> var count = true; document.getElementsByAttribute=function(attrN,attrV,multi){ attrV=attrV.replace(/\|/g,'\\|').replace(/\[/g,'\\[').replace(/\(/g,'\\(').replace(/\+/g,'\\+').replace(/\./g,'\\.').replace(/\*/g,'\\*').replace(/\?/g,'\\?').replace(/\//g,'\\/'); var multi=typeof multi!='undefined'? multi: false, cIterate=typeof document.all!='undefined'? document.all: document.getElementsByTagName('*'), aResponse=[], re=new RegExp(multi? '\\b'+attrV+'\\b': '^'+attrV+'$'), i=0, elm; while((elm=cIterate.item(i++))){ if(re.test(elm.getAttribute(attrN)||'')) aResponse[aResponse.length]=elm; } return aResponse; } function edit() { if(count) { // Get all input elements into an object var inputs = document.getElementsByTagName('input'); // Loop through inputs for( var i=0; i<inputs.length; i++ ) { // create new element to insert before var button = document.createElement('button'); // Set the inner HTML of the button to 'edit' button.innerHTML = 'Edit'; // Set onClick action button.setAttribute('onclick', "doAlert('"+ inputs[i].id +"')"); // Append the button before the current input document.body.insertBefore(button, inputs[i]); } var inputs = document.getElementsByTagName('textarea'); // Loop through inputs for( var i=0; i<inputs.length; i++ ) { // create new element to insert before var button = document.createElement('button'); // Set the inner HTML of the button to 'edit' button.innerHTML = 'Edit'; // Set onClick action button.setAttribute('onclick', "doAlert('"+ inputs[i].id +"')"); // Append the button before the current input document.body.insertBefore(button, inputs[i]); } var inputs = document.getElementsByTagName('img'); // Loop through inputs for( var i=0; i<inputs.length; i++ ) { // create new element to insert before var button = document.createElement('button'); // Set the inner HTML of the button to 'edit' button.innerHTML = 'Edit'; // Set onClick action button.setAttribute('onclick', "doAlert('"+ inputs[i].id +"')"); // Append the button before the current input document.body.insertBefore(button, inputs[i]); } var inputs = document.getElementsByTagName('label'); // Loop through inputs for( var i=0; i<inputs.length; i++ ) { // create new element to insert before var button = document.createElement('button'); // Set the inner HTML of the button to 'edit' button.innerHTML = 'Edit'; // Set onClick action button.setAttribute('onclick', "doAlert('"+ inputs[i].id +"')"); // Append the button before the current input document.body.insertBefore(button, inputs[i]); } count = false; } } function doAlert(elementID) { var tag = document.getElementById(elementID); if(tag.tagName == 'LABEL') { window.open('editor.php?value='+ document.getElementById(elementID).innerHTML + '&id=' + elementID + '&tag=' + tag.tagName, 'popup title', 'toolbar=0, scrollbars=0, location=0, statusbar=0, menubar=0, resizable=0, width=400, height=300'); } else { window.open('editor.php?value=' + document.getElementById(elementID).value + "&id=" + elementID + "&tag=" + tag.tagName, "popup title", "toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=400,height=300"); } } </script> basically this is the structure of my php file: <html> <head> <script> </script> </head> <body> <?php echo display_html(); ?> </body> </html>
  5. thank you :3 and i know it is much different than my original question, but that was because i wanted to at least try my hands out at it but i couldn't wrap my mind around how i would be able to do it lol the button portion was one of the main problems and i figured if i knew how to get the buttons there then i could get the rest of it on my own xP which didn't work out entirely in my favor
  6. I got it to work, xP what i mean by pulling out the information I need i mean say you have somethinglike: <html> <head> </head> <body> <button>Edit</button><input type="text" id="fname" value="first name"><br> <button>Edit</button><input type="text" id="lname" value="last name"> </body> </html> With this, I want to be able to click on edit button and it will bring up another window that will display, say, the value of fname, if i were to click on the edit button that is right beside the fname tag. Or if i were to click on the second button, that it would bring up with the value that lname has. I hope this makes sense? lol
  7. Your version, I feel, might be better suited for what I am trying to do since you should be able to pull out the information I need anyways, but I tried to get yours to work and it doesn't. I haven't dove into javascript or the dom very much so maybe it is on my side that it is not working?
  8. Is there any way that I could get any values of the objects that the button is placed next to? Like any attributes? That way I could store a value and depending on what button you clicked it would show something different? The whole reason I am doing this is to create an edit feature so that I could show what fields a user is able to edit, by the buttons, and then when a user clicks on this button they can change certain attributes, for example a textarea you can change the value that it holds.
  9. ahhhhhh i feel retarded....forgot to have the whole $(document).ready(function() { thing initialized, but now it works! xP thank youuu~~~ <3
  10. It didn't do anything xP but it definitely is a step in the right direction, i did not know about the before function so thank you for that ^^ I will try and play around with this so i can hopefully get it to work somehow lol
  11. I guess here is the best place to answer, but is there a way to make javascript place an html tag right next to another html tag. Here is what I mean, say you have: <html> <head> </head> <body> <input type="text" /> </body> </html> what I want to do is go through the html using javascript, or anything that could accomplish this, to look for an input, then place a button next to it. So that my output would be: <html> <head> </head> <body> <button>Edit</button><input type="text" /> </body> </html> any thoughts on this?
  12. For some reason i'm getting: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' Here is the query that i'm running: 'INSERT INTO template_information (html, css, div_tag) VALUES( "' . $html . '", "' . $css . '", "' . $div_tags . '" )' It worked fine till I added 'div_tag', but as far as I can see I added it to the query correctly so I don't know why its giving me this error.
  13. i figured it out, mainly just changed my array around so it wasn't a big deal. the reason i wouldn't know the key or the values is due to that the array could change to anything that a user might input in to it. the array was just a way to store the data temporarily and made it easier to just loop through the array to find the values.
  14. ...ok i'm retarded xD bleh, thanks you two~ X_x but then why wouldn't a foreach work for it? How would i be able to get that key though? without also knowing the value associated with the key? for example, I only know '0' but not 'something1' or 'something2' nor the values that point to those keys?
  15. For some reason this is stumping me =__= but I am having troubles navigating through an array. My array is set up like: array( 0 => array( "something1" => array("stuff" , "stuff") "something2" => array( "more stuff", "more stuff")) i've tried doing a foreach on the array but it only pulls "something1" and not "something2" for some reason, and when i try array[0][1] to try and get "something2" it just says i'm out of the index.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.