Jump to content

kigogu

Members
  • Posts

    39
  • Joined

  • Last visited

    Never

Everything posted by kigogu

  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.
  16. I ended up just going with JQuery and creating a function to change the content based on the button that was clicked ^^
  17. NVM! I got the answer, since the second button was created dynamically, it wasn't being registered, so if i just use on instead of click then it works perfectly, here is the new code: $(document).ready(function() { $(document).on("click", "#1", function() { $("#leftPart").html('<input type="button" name="submit" id="2" value="Submit" />'); $("#rightPart").html(''); }); $(document).on("click", "#2", function() { $("#rightPart").html('<input type="text" id="new_world" value="new_world" name="new_world" >'); }); });
  18. I'm trying to change content with jquery by changing the content of a div id. Basically what I want to do is when a user clicks on a button, it will change the content and display a new button, then when they click on the new button it will display different content. essentially this will be like a three page website if this were all to work. so far I have: $(document).ready(function() { $("#1").click(function() { $("#leftPart").html('<input type="button" name="submit" id="2" value="Submit" />'); $("#rightPart").html(''); }); $("#2").click(function() { $("#rightPart").html('<input type="text" id="new_world" value="new_world" name="new_world" >'); }); }); In the HTML it will already have a button with an id = 1, so once you click on that it displays the second submit button in the leftPart div, but when you click on the second submit button (id = 2, in the jquery) it doesn't change anything. I'm completely new to jquery, so i could definitely use some help on this.
  19. Awesome ^^ I will definitely try this when I get a chance. Thank you
  20. ....totally forgot about sessions =___= thanks xD sorry for being all complicated in my explanation
  21. sorry lol, alright so I have one page where someone inputs a number, X, then hits submit. Once they hit submit it goes to a form page where they can enter information. What I want to do is take the number from the first page and display the form page that number of times. I will have a submit button where once they click that, I will then get their information, and then display the form again until they have gone through the form page X number of times.
  22. Not really, what I want to do is loop through a form that I would have in html multiple times, so like when I click submit on one form it would basically grab that information and then refresh to the same form for them to input again. I guess it would just be a matter of what would i put in the submit button to call?
  23. I want to be able to display the same thing multiple times, but the amount depends on what the user had input in on the previous page. How would I go about accomplishing this? I can use a $_GET['X'] to get the variable amount, but I don't know how to use it to where I can loop through something X amount of times.
  24. This is a problem that I have been struggling with, I am working on something that will hold all the content for multiple pages in a website with only just one file. This file will just contain the content that will be displayed. The content will then be parsed to a template file that holds the style of the website, but I am having trouble displaying only certain parts of the content. I can load all of the content for all of the pages at once, but I do not know how to choose which content to display when I want it to be displayed. I have looked in to JQuery, but I do not know how to use it for what I am trying to do. Is there a way I could just pass in php values to a function that will just rewrite everything? An example of this would be something like (3 pages): one page I have a contact form that will have fields like first name and last name, so on. At the bottom is the submit button, once they click on that they move to the next page. the next page will have some information that will be displayed in text. At the bottom of this page is another submit button, once they click on that they move to the next page. the last page will just thank the user for spending their time on the website and there is no button at the bottom. The file that will contain all of the content will hold the values and fields that will be required to display each one of these pages. I am trying to place each one of the three contents one at a time. So the second page will not display until the user clicks the submit button from the first page, and the last page wont display until the user clicks the submit button on the second page. I have no idea how to do this lol The file that contains the content does not hold the actual html values, only the attribute values and the type that it should be. I run that through a php program that will turn that in to an html string that will then parse it to the template file. Hopefully I have provided at least some description as to what i'm trying to accomplish lol
  25. strpos does this for non-variable substrings. This really is the wrong way of going about things. So I guess it sounds...kind of functional but scary and slow. If it works, it works, we're not going to force you to rewrite it to be correct. haha, *sigh* i kind of figured that OTL well each page isn't going to run this when someone goes to it, just to save the personalized file i guess. I definitely do not mind rewriting anything that i've been doing as long as its more efficient or just an easier way to go about doing things, but I know what i'm asking for is definitely not an efficient way anyways so its more of i'll take what i can get xD even if its a conceptual idea of how one might go about doing this.
×
×
  • 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.