Jump to content


 


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.


Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Photo

AJAX and HTML


  • Please log in to reply
4 replies to this topic

#1 KamakaZ

KamakaZ

  • Members
  • 739 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Victoria
  • Local time:07:01 AM

Posted 25 May 2010 - 01:32 AM

I have read tutorial after tutorial, all i want to do is have a drop down box up the top of my page with the numbers 1-10 in it, then based on whats selected display x number of text boxes within a form i can then post to another ASP or PHP page.

Any idea's? I'm kinda stuck on this and don't have any code that works.

I was thinking about trying it with java script:

<!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 content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Untitled 1</title>

<script type="text/javascript">

function printStuff(){
	var grade, status, score;
	
	grade = document.getElementById("selection").value;
	
	if ( grade === "A" ){
	   document.getElementById("statusField").innerHTML = "Good";
	   document.getElementById("scoreField").innerHTML = "4";
	} else if (grade === "B"){
	   document.getElementById("statusField").innerHTML = "Good";
	   document.getElementById("scoreField").innerHTML = "3";
	} else {
	   document.getElementById("statusField").innerHTML = "Average";
	   document.getElementById("scoreField").innerHTML = "2";
	}
}

</script>
</head>

<body>


	<select id ="selection" style="width: 133px" onchange = "printStuff()">
	<option></option>
	<option value="A">A</option>
	<option value="B">B</option>
	<option value="C">C</option>
	</select>
	
	<br />
	<span id = "statusField"></span>
	<br />
	<span id = "scoreField"></span>

	

</body>

</html>

But this would be a very lengthy IF statement, would it be possible to maybe change it to "do while i <= x" rather than AJAX?

There's no place like 127.0.0.1
There are 10 types of people in the world, those that can read binary, and those who can't.


BC AdBot (Login to Remove)

 


#2 Romeo29

Romeo29

    Learning To Bleep


  • BC Advisor
  • 3,194 posts
  • OFFLINE
  •  
  • Gender:Not Telling
  • Location:127.0.0.1
  • Local time:03:01 PM

Posted 25 May 2010 - 02:33 PM

Your code is entirely different from what you intend to do.

Why do you have radio buttons (<option>) in your form ? Where have you put text box (<input type="text">) ? You do not even have a <form> in your code.

#3 KamakaZ

KamakaZ
  • Topic Starter

  • Members
  • 739 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Victoria
  • Local time:07:01 AM

Posted 25 May 2010 - 07:18 PM

I was suggesting maybe it's possible to change that code to do what i intend to do. The <option></option> is a dropdown box, that when changed it runs the javascript and updates the "innerHTML" of the two div's.

In my case i would have the dropdown box change the number of textboxes (<input type="text" ...>) in the div, but i also want it to retain any information the user may have already typed into the current textboxes.

In the code above i don't have a <form></form> but i know how to do that, the part i'm having trouble with is the addition and subtraction of html within a <div></div> without refreshing the page.

Edited by KamakaZ, 25 May 2010 - 07:21 PM.

There's no place like 127.0.0.1
There are 10 types of people in the world, those that can read binary, and those who can't.


#4 groovicus

groovicus

  • Security Colleague
  • 9,963 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Centerville, SD
  • Local time:02:01 PM

Posted 26 May 2010 - 06:02 AM

But this would be a very lengthy IF statement,

It isn't as though there is some limit in how many levels there are to an if else code block. If the content based on number is going to be substantially different (as in your example), then you have no choice other than maybe using a switch statement instead. At any rate, I have worked on projects containing tens of thousands of lines of Javascript.

would it be possible to maybe change it to "do while i <= x" rather than AJAX?

Umm, what? There is no AJAX in your example at all. But you can accomplish what you want in one of two ways; you can do it purely through Javascript, or you could make an Ajax call back to the server to get the content to display. If you are wanting to display some huge amount of data based on some external data set, then you will probably want to use Ajax. If it is just some small difference, then use Javascript.

If you want to retain the value of the text fields, then as each text box is filled, store it in a Javascript variable. You can retrieve the value any time as needed and refill the text field. I don't have time to put together an example right now, but it is pretty trivial.

#5 KamakaZ

KamakaZ
  • Topic Starter

  • Members
  • 739 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Victoria
  • Local time:07:01 AM

Posted 26 May 2010 - 05:57 PM

Sorry, I didn't really explain myself properly above. Basically what I'm doing is making a quoting form, for every serialized stock item it will need a new set of textboxes (stock code, qty, description etc...). I'm wanting to diplay the drop down box at the top of the screen, when a number in the drop down is selected it shows that many fields.

If the user gets halfway through the quote though and decides they need one more/less, I'm wanting the page to update with the text that the user has typed in already and an extra/one less set of fields.

I haven't had much experience in either AJAX or Javascript, the example I provided above I was hoping could be modified to accomplish what I'm after, just don't know where to start.

There's no place like 127.0.0.1
There are 10 types of people in the world, those that can read binary, and those who can't.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users