Jump to content

Optimizing a Nightmare...


MinusMyThoughts

Recommended Posts

I created a dropdown box (with the help of people on this forum, of course), and i think i've come to a point that i need a better method......right now i'm using a conditional javascript based on the selection in a dropdown box. it works great for what it is, but i want to automatically populate my text fields with the information from the page the user is trying to update......here's what it looks like now. brace yourself:

<script type="text/javascript"><!--function change_pages(val){if(val == "Home"){document.getElementById('updater').innerHTML = "<form action=\"preview.php\" method=post><table border=\"0\" class=\"w495\"><tr><td align=\"right\" width=\"200\"><p><b>Body:</b></p></td><td align=\"center\" class=\"w360\"><textarea rows=\"8\" cols=\"20\" name=\"homeBody\" class=\"w360\"></textarea></td></tr><tr><td align=\"right\" colspan=\"2\"><input type=\"hidden\" name=\"contentID\" value=\"1\"><input type=\"submit\" value=\"Update Home\"></tr></table></form>";} else if (val == "About"){document.getElementById('updater').innerHTML = "<form action=\"update.php\" method=post><table border=\"0\" class=\"w495\"><tr><td align=\"right\" width=\"200\"><p><b>Body:</b></td><td align=\"center\" class=\"w360\"><textarea rows=\"8\" cols=\"20\" name=\"aboutBody\" class=\"w360\"></textarea></td></tr><tr><td colspan=\"2\" align=\"right\"><input type=\"submit\" value=\"Update About\"></tr></table></form>";} else if (val == "Services"){document.getElementById('updater').innerHTML = "<form action=\"update.php\" method=post><table border=0 class=\"w495\"><tr><td align=\"right\" width=200><p><b>Picture 1 URL:</b></td><td align=\"center\" class=\"w360\"><input type=\"text\" class=\"w360\" name=\"servicesPic1\" value=\"http://\"></td></tr><tr><td align=\"right\" width=200><p><b>Picture 2 URL:</b></td><td align=\"center\" class=\"w360\"><input type=\"text\" class=\"w360\" name=\"servicesPic2\" value=\"http://\"></td></tr><tr><td align=\"right\" width=200><p><b>Body:</b></td><td align=\"center\" class=\"w360\"><textarea rows=\"8\" cols=\"20\" class=\"w360\" name=\"servicesBody\"></textarea></td></tr><tr><td align=\"right\" colspan=2><input type=\"submit\" value=\"Update Services\"></td></tr></table></form>";} else if (val == "Media Credits"){document.getElementById('updater').innerHTML = "<form action=\"update.php\" method=post><table border=0 class=\"w495\"><tr><td align=\"right\" width=200><p><b>Article Title:</b></td><td align=\"center\" class=\"w360\"><input type=\"text\" class=\"w360\" name=\"mediaTitle\"></td></tr><tr><td align=\"right\" width=200><p><b>Publication:</b></td><td align=\"center\" class=\"w360\"><input type=\"text\" class=\"w360\" name=\"mediaPublication\"></td></tr><tr><td align=\"right\" width=200><p><b>Cover URL:</b></td><td align=\"center\" class=\"w360\"><input type=\"text\" class=\"w360\" name=\"mediaCover\" value=\"http://\"></td></tr><tr><td align=\"right\" width=200><p><b>Article URL:</b></td><td align=\"center\" class=\"w360\"><input type=\"text\" class=\"w360\" name=\"mediaArticle\" value=\"http://\"></td></tr><tr><td align=\"right\" width=\"200\"><p><b>Article Excerpt:</b></td><td align=\"center\" class=\"w360\"><textarea rows=\"8\" cols=\"20\" class=\"w360\" name=\"mediaBody\"></textarea></td></tr><tr><td align=\"right\" colspan=2><input type=\"submit\" value=\"Update Media Credits\"></td></tr></table></form>";} else if (val == "Testimonials"){document.getElementById('updater').innerHTML = "<form action=\"update.php\" method=post><table border=0 class=\"w495\"><tr><td align=\"right\" width=200><p><b>Name:</b></td><td align=\"center\" class=\"w360\"><input type=\"text\" class=\"w360\" name=\"testName\"></td></tr><tr><td align=\"right\" width=200><p><b>Position:</b></td><td align=\"center\" class=\"w360\"><input type=\"text\" class=\"w360\" name=\"testPosition\"></td></tr><tr><td align=\"right\" width=200><b>Picture URL:</b></td><td align=\"center\" class=\"w360\"><input type=\"text\" class=\"w360\" name=\"testPicture\" value=\"http://\"></td></tr><tr><td align=\"right\" width=\"200\"><p><b>Testimonial:</b></td><td align=\"center\" class=\"w360\"><textarea rows=\"8\" cols=\"20\" class=\"w360\" name=\"testBody\"></textarea></td></tr><tr><td colspan=\"2\" align=\"right\"><input type=\"submit\" value=\"Update Testimonials\"></tr></table></form>";} else if (val == "Links"){document.getElementById('updater').innerHTML = "<form action=\"update.php\" method=post><table border=0 class=\"w495\"><tr><td align=\"right\" width=200><p><b>Link Name:</b></td><td align=\"center\" class=\"w360\"><input type=\"text\" class=\"w360\" name=\"linkName\"></td></tr><tr><td align=\"right\" width=200><p><b>Link URL:</b></td><td align=\"center\" class=\"w360\"><input type=\"text\" class=\"w360\" name=\"linkUrl\" value=\"http://\"></td></tr><tr><td align=\"right\" width=200><p><b>Banner URL:</b></td><td align=\"center\" class=\"w360\"><input type=\"text\" class=\"w360\" name=\"linkBanner\" value=\"http://\"></td></tr><tr><td align=\"right\" colspan=2><input type=\"submit\" value=\"Update Links\"></table></form>";} else if (val == "Newsletter"){document.getElementById('updater').innerHTML = "<form action=\"lettersender.php\" method=post><table border=\"0\" class=\"w495\"><tr><td align=\"right\" width=200><p><b>Subject:</b></td><td align=\"center\" class=\"w360\"><input type=\"text\" class=\"w360\" name=\"subject\"></td></tr><tr><td align=\"right\" width=\"200\"><p><b>Body:</b></td><td align=\"center\" class=\"w360\"><textarea rows=\"8\" cols=\"20\" name=\"body\" class=\"w360\"></textarea></td></tr><tr><td colspan=\"2\" align=\"right\"><input type=\"submit\" value=\"Send Newsletter\"></tr></table></form>";} else {document.getElementById('updater').innerHTML = "<b>Please select which page you would like to edit</b>";}}//--></script>

...the dropdown box is sitting inside a <div> labeled "updater" that changes based on the selection in the box......now, messy as i've made this, it does the trick (or it did, at least). my form actions are strange because i'm trying to only develop "Home" for now, until i've got that running smoothly, then integrate into the rest of the site......my goal is to give the textarea in "Home" a value of $_SESSION['homeBody']. i realize now that it's going to be either impossible or impossible to read......so, i guess, my primary goal is to find a way to get the same kind of dropdown box without needing all the mess. is that possible?...can someone kick me in the right direction?...thanks again!love,jason

Link to comment
Share on other sites

For certain tasks, a certain amount of mess can be unavoidable. Writing content with Javascript is one of those things, so is using PHP to write Javascript code which writes HTML content. There are enough custom things in each block that it would almost be messier to use functions to put together the innerHTML text.If you just want to put the variable in the javascript text, you can do something like this:<textarea rows=\"8\" cols=\"20\" name=\"homeBody\" class=\"w360\"><?php echo addslashes($_SESSION['homeBody']); ?></textarea>Experiment with different quotes and things to make sure it comes across right, but that should do it.

Link to comment
Share on other sites

i can't seem to get that to work. it kills the javascript, somehow. i tried to escape the session call ($_SESSION[\'homeBody\']), but that gave me an error. i tried moving the <?php ?> tags around to fix it, but it seems like so long as there is a php tag in the code, the javascript won't work......any suggestions?...thanks!love,jason

Link to comment
Share on other sites

Just a thought, why not put an iframe in there, and have javascript redirect that frame (depending on what val is set at) to separate static html (or a php file in the case where you want to preserve that content) files on the server? That way, the html code is removed from the javascript - clearing off a lot of clutter. Also, when you want to update any of the forms, you can just edit that particular html file. You don't have to worry about escaping quotes and having that cause javascript errors also.Also, I'm sure javascript has a switch control statement. Use that instead.

Link to comment
Share on other sites

Your very own w3schools has an example on it: http://w3schools.com/js/tryit.asp?filename=tryjs_two_iframesExcept in your case, there won't be two frames. Maybe something like this?:

//Javascriptfunction change_pages(val){var url;switch(val){  case 'Something':	url='/something.php';	break;	  case 'Something':	url='/something1.php';	break;	  default:  case 'Home':	url='/something2.php';	break;	}document.getElementById("form_frame").src=url;}//html iframe portion:<iframe src='/something2.php' id="form_frame"></iframe>

Link to comment
Share on other sites

well if you have for example a test.html in frames directory, you can get it by

<iframe src="frames/test.html"></iframe>

test.html is now located in parent directory, so

<iframe src="../test.html"></iframe>

so what goes for img and other path "commands", they work in iframes as well :)

Link to comment
Share on other sites

Well, I'm not an expert in this area and I don't have time to futz around to figure it out. What I'm assuming is that the iframe acts as an independent browser page, meaning that it has no knowledge relatively of the frame that contains it. If that's NOT the case, then there might be something you overlooked when you wrote your relative paths.I expect though, that there's no way for the iframe to look at it's container to decide where to go for relative paths (I mean, without some messy javascript sending information there). Thus, I suspect that you're forced to use full-paths. At least, this is how I would approach the problem, though I'm sure those that are trained in AJAX and whatnot could probably do a better job:

//Javascriptfunction change_pages(val){var url="http://somethingsomething.com/";switch(val){  case 'Something':	url.='something.php';	break;	  case 'Somethingelse':	url.='something1.php';	break;	  default:  case 'Home':	url.='something2.php';	break;	}document.getElementById("form_frame").src=url;}//html iframe portion:<iframe src='http://default frame/full path.php' id="form_frame"></iframe>

Link to comment
Share on other sites

The 404 or Not Found error message is an HTTP standard response code indicating that the client was able to communicate with the server.404 File Not Found: Server cannot find the file you requested. File has either been moved or deleted, or you entered the wrong URL or document name. Look at the URL. If a word looks misspelled, then correct it and try it again. If that doesn't work backtrack by deleting information between each backslash, until you come to a page on that site that isn't a 404. From there you may be able to find the page you're looking for.About relative addressing, the file path must be relative from the current file location and from there you need to get the destination file path...Another option is to initially declare as string the "basic path" i.e common path and use it to locate files....example: Initial decleration$path = "http://domainname/mainfolder";when using it in any place.$currentpath = $path . "subfoldername/filename"

Link to comment
Share on other sites

I expect though, that there's no way for the iframe to look at it's container to decide where to go for relative paths (I mean, without some messy javascript sending information there). Thus, I suspect that you're forced to use full-paths. At least, this is how I would approach the problem, though I'm sure those that are trained in AJAX and whatnot could probably do a better job:
I imagine that a relative path in an iframe would be relative to the iframe file, not the file that contains the iframe. It would make more sense to do it that way.
Link to comment
Share on other sites

i don't know what i was doing wrong before......i shut down and moved to another location, opened up my laptop and changed the URLs back to the relative addresses. everything works fine, now......now i want to know what i was doing wrong......oh well, i guess. it works!...thanks you guys!love,jason

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...