Get search box id present on website using javascript and C# - javascript

I am new to Javascript and C# and wanted to know how to get search box id of the search box present on website.
Kindly refer the approach i followed
var url = "example.com";
System.Net.WebRequest req = (HttpWebRequest)WebRequest.Create(url);
HttpWebResponse res = (HttpWebResponse)req.GetResponse();
if (res.StatusCode == HttpStatusCode.OK)
{
<script type="text/javascript">
function searchAlive() {
var link_s = document.getElementById('search').value;
}
</script>
}

You can get the search box id by using Javascript/Jquery using some properties(css,text etc..) of the text box. include html so that we can help you better

If you want use JavaScript:
var _Searched = document.getElementById("SearchTextBoxID").val();
if you are using C#:
string _Searched = SearchTextBoxID.text;
you have to show your codes and your approach. what environment you are coding in and what language you are using ?
If you mean you don't know the "SearchBoxInput" ID and you want to get it, you can use other element such as the class name or tag name to get the element value. But as a programmer, you have to know and work with 'ID' when using backend codes like c# and javascript.
if you want to get the id:
var inputs = document.getElementByTagName("input");
for(i=0;i<=inputs.lenght;i++){
if(inputs[i].class == "searchClass"){ var id = input[i].id }
}

Related

How to take input in a page using javascript and display the input in the html?

I am trying to make a simple web page, and I want to take input from the user and display the same in the web page, how should I write the Javascript code for the output? Currently it looks like this
var username = prompt("Your username")
var comment = prompt("Your comment")
println(username + comment)
You can use the document API (this API represents any web page loaded in the browser and serves as an end point into the web page's content, which is the DOM tree) for that and fetch one of the elements in your html file. then you can assign its innerText to the answers you got.
For example (using the getElementById)
var username = prompt("Your username");
var comment = prompt("Your comment");
document.getElementById("answer").innerText = username + ' ' + comment;
<div id="answer">
</div>
More about the document interface here
Not sure exactly what you're looking for but you can edit the HTML value using :
document.getElementbyId('id').innerHTML = '';

how to render a form using JSON in JQuery Form builder

i have simple web application where i can create forms and save its JSON in a database then get the same JSON and Render it back , all built using the Jquery FormBuilder that is available online. Right Now , I am Struggling with render part because it doesnt display anything , and my knowledge in java script is pretty limited to fix it .
here is what i have done so far
for the PHP side , i can take the Json schema and give it to a variable , i tested it and the value is there and can be printed
$json=$row['survey_schema'];
for the java script part
var container = $('#formrender');var options = {
container,
dataType:'json',
formData:'<?php $json ?>' }; container.formRender(options);
as for the HTML
<div id="formrender"></div>
from what i understand the script looks for the div named formrender and renders the form based on the provided JSON that i gave it to it .
but nothing happens and it is just a blank screen
thank you , and sorry for my bad english
This is available in jQuery Form builder documentation, and this is how I did it:
<script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.4.0/highlight.min.js"></script>
<script src="https://formbuilder.online/assets/js/form-render.min.js"></script>
<script>
jQuery($ => {
const escapeEl = document.createElement("textarea");
const code = document.getElementById("formrender");
const formData = "";//Your JSON data goes here
const addLineBreaks = html => html.replace(new RegExp("><", "g"), ">\n<");
// Grab markup and escape it
const $markup = $("<div/>");
$markup.formRender({ formData });
// set < code > innerText with escaped markup
code.innerHTML = addLineBreaks($markup.formRender("html"));
hljs.highlightBlock(code);
});
</script>

Name Game Social Share

I am working on a Name Game type of Name Generator where you enter some fields and associated variables are pulled. I have the generator working and the share links working, however I can't get them to populate with the final 'sillyname' variable.
AKA When you click share, it has a generic message but I am trying to get it to dynamically enter the name into the tweet or facebook share text.
Any help on this would be awesome.
Here is the link for you to dig deeper.
http://codepen.io/drewlandon/pen/VLvpjq
I have this in the twitter/facebook share function:
var twitterWindow = window.open('https://twitter.com/intent/tweet?url=http://sweetleafmarijuana.com/&text=My Sweet and Fierce Name... &via=TheSweetestLeaf &hashtags=SweetFierceName', 'twitter-popup', 'height=350,width=600'); if(twitterWindow.focus) { twitterWindow.focus(); }
return false; } var facebookShare = document.querySelector('[data-js="facebook-share"]');
However I found this and feel like it needs to be something along these lines:
function twitterShare(){
var shareText='My funny pseudonym is '+accents_to_regulars(outputName)+', according to #...'
So i'm thinking i need something like this (but having trouble from there)
var twitterMessage = "My #SWEETFIERCENAME is " + hungryName + ", according to #thesweetestleaf's #SweetFierceName Name Generator";
var facebookMessage = "My name is " + hungryName + "";
You need to escape the text for the URL.
It works here: http://codepen.io/anon/pen/Kpdvqa
twitterShare.onclick = function(e) {
e.preventDefault();
var twitterWindow = window.open('https://twitter.com/intent/tweet?url=http://sweetleafmarijuana.com/&text='+encodeURIComponent(getSillyName())+'&via=TheSweetestLeaf &hashtags=SweetFierceName', 'twitter-popup', 'height=350,width=600');
if(twitterWindow.focus) { twitterWindow.focus(); }
return false;
}
The # character has special meaning in URLs.
As for the Facebook message, there is no way to pre-fill that anymore:
http://www.quora.com/With-Facebooks-share-link-is-there-a-way-to-prefill-the-text-to-be-posted
You will have to take a closer look at the FB Feed Dialog to see other options, like perhaps updating the caption property instead.

Need to pass long text variables from JavaScript to PHP

Amateur here... I have an SQL query on an JS page and need to pass the variables onto a PHP webpage. I know how to pass the more simple variables through the URL, but am struggling in finding and executing the most efficient way to passing a long string, i.e. the text description of a point
Here on the JS side, I have:
downloadUrl("php_genxml1.php", function(data) {
var xml = data.responseXML;
var points = xml.documentElement.getElementsByTagName("point");
for (var i = 0; i < points.length; i++) {
var id = points[i].getAttribute("id");
var name = points[i].getAttribute("name");
var description = points[i].getAttribute("description");
var url = "PHPWebPage.php?name=" + name + "&id=" + id;
To get the id from the URL, I have used stuff like the standard
$id=$_GET['id'];
I know I could re run a query based off that id from the URL, but that surely doesn't sound the most efficient. I know my options (array, sessions, etc) for whatever that's worth.
Thanks for any help, C
Try POSTing the data instead. It also makes it less likely for someone to just edit your URL in the browser to get data they're not supposed to have.

Get info a field of a page with javascript or jquery

i need to get an information of another page with javascript or jquery, to show that field on another page
the id of the field is "profile_field_13_1" and it shows the member status
I would like to get that "status" to put in an html page, how can i do that?
I already tried this:
jQuery(document).ready(function(){if(jQuery('#profile-advanced-right').length){
var status=jQuery('.middleline #profile_field_13_1 dd div:eq(0)').html();
<div class="status"><span id="cs">'+status+'</span></div>
');
}});
This is where you can use ajax.
var url = "mypage.html";
$.get(url,function(data){
var contentFromTheOtherPage = data;
//process it here
});

Categories