473,327 Members | 2,090 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

adding image based on if condition specifically to input box without opening new page

Hi All,

this is my client code,
Expand|Select|Wrap|Line Numbers
  1. <li>
  2. <label for="city"><span class="required">City/State</span></label>
  3. <input id="city" name="city" type="text" class="text required" disabled="disabled">
  4. </li>
this is my server side code,
Expand|Select|Wrap|Line Numbers
  1. function handler(evtXHR)
  2. {
  3.   if(xhr.readyState == 4)
  4.    {
  5.      if(xhr.status == 200)
  6.       {
  7.          var response = xhr.responseXML;
  8.          //var response =  xhr.responseText;
  9.          console.log(response);
  10.          toggleDiv("page");
  11.          toggleDiv("pageDtl");
  12.          $("input#city").val(response.getElementsByTagName("city").item(0).firstChild.data);
  13.  
  14. var desc = response.getElementsByTagName("desc").item(0).firstChild?response.getElementsByTagName("desc").item(0).firstChild.data : "";
  15.          if(desc == "Cloudy")
  16.          {
  17.              alert("cloudy");
  18.              $("input#desc").val(response.getElementsByTagName("desc").item(0).firstChild?response.getElementsByTagName("desc").item(0).firstChild.data :);
  19. document.write("<img src='images/sunny.gif'>");
here i have if condition to check the weather forecast and its working but i also wanted to add image @ specific location that means in input box but the document.write opens a new page. please somebody help me how to add image in javascript based on if condition without navigating the page to locate the image in input box of server side
Apr 13 '12 #1
3 1696
Dormilich
8,658 Expert Mod 8TB
a) JavaScript (including AJAX) is client-side code
b) trash document.write(). it kills your page. use jQuery to insert the image
Apr 13 '12 #2
johny10151981
1,059 1GB
as dormilich said, if you document.write, it will remove all the data from your page and add the certain information.

and you know that you can give id to any object on the document. why dont you initiate a different id to all the objects, and you simply can write your data to that desired object.

as example:
Expand|Select|Wrap|Line Numbers
  1. $('#your_object').html(data);
if you use above jquery code you will get one advantages. your embedded javascript code returned from the server will also be executed.
Apr 16 '12 #3
Hi johny10151981,
could you let me know how and where to use this
Expand|Select|Wrap|Line Numbers
  1. $('#your_object').html(data);
Apr 27 '12 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: SPEAKIT | last post by:
I'm sorry to ask what must be a very simple question, but I just can't seem to get this to work. Right now I am using the javascript 'prompt' to enter a photoid and the script that I am using uses...
0
by: adi4u | last post by:
Give an idea on how image based search can be implemented??
4
by: abstractj | last post by:
I found the below script that will display an image based on certain date. I would like to add an additional function that will display the images when it is referred by a certain URL. IE. if users...
3
by: Valli | last post by:
Hi, I want to add an image to a html type input button. How can I do this? I have used background image style . But its not working. My target is to show an image in the button can anyone...
2
by: Jankie | last post by:
Hi and wish all moderators and members are doing well i Back with a question after a long while,hope to find the valuable typical support from thescripts people and members. My host does not...
1
by: saikris | last post by:
I have a requirement in which I need to check some files and provide the report on UI. And I would like to design this in such a way that on Windows form it displays all file names and then it...
1
by: Ben Brown | last post by:
I'm having some problems.. I have some javascript generated input elements with dynamic names and values. ex: <input name = "t1Name" .../> <input name = "t2Name" .../> ..... <input name =...
1
by: svjim | last post by:
I am working on an iPhone application which uses a version of safari (UIWebView) to display web pages. I want to be able to capture images shown on the webview. To do so, I can capture a "touch...
6
by: londres9b | last post by:
Let's say I have a page called page.php. And let's also say I have an images folder. How can I make the php page display the images on the folder? But that's not the whole thing... What I really...
1
by: Mike Stunn | last post by:
Hello, I have been trying to find a piece of code which would show an image based on referring url. How would I go about displaying say Image1.png if a user came from "http://www.mysite.com" ?...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.