Name Game Social Share - javascript

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.

Related

Creating a javascript search bar for website and having trouble linking to correct page based on user input

I am trying to take the user input from the search bar, translate it into a string and then open up the webpage i have created using the input they have given me.
Here is what i am looking to do.
if(userData){
icon.onclick = ()=>{
webLink = 'myPages/userData.html'
linkTag.setAttribute("href", webLink);
linkTag.click();
}
When i try to add in the variable userData, which is the user input from the search bar, doing it like this:
if(userData){
icon.onclick = ()=>{
webLink = 'myPages/' + userData + '.html'
linkTag.setAttribute("href", webLink);
linkTag.click();
}
This comes off as an error and says it cannot find the file to redirect to.
I am new to javascript and need to figure out how to pass the variable in and create the correct address to open up the new html file page.
I have already taken out the spaces and formatting from the user input, as well as tried to create a new variable containing the address but both did not work and i still got the same error saying there are quotations in the address so it cannot be found.

Modify URL based on search filter

I have a product search page. In which I have search field. After searching the list of product is displaying in result section. Now I want to modify the search using left side panel "Refine your search" , in this section there are some parameter that will narrow your search.
Let user searching Shirt then my URL is http://localhost:8080/query?q=shirt
Now if user refine the result with color RED. I need to update the URL with
http://localhost:8080/query?q=shirt&color=red
How to do ?
I am using Spring MVC and JSP , Javascript is also an option.
If you aren't adverse to using jQuery, then you can implement this. It doesn't completely account for the actual search query though since I don't fully know your implementation.
var currentColor = '';
$("input[type=radio]").on('click', function () {
var previousColor = currentColor;
currentColor = $(this).val();
//if the parameter has already been set then replace, otherwise create a new one
if (previousColor) {
location.href = location.href.replace("color=" + previousColor, "color=" + currentColor);
} else {
location.href = location.href + '&color=' + currentColor;
}
});

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

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 }
}

can't get ajax to work with jsp

Ok, so I'm learning web design as a co-op at a company. However, the department I'm in is lacking in knowledgeable people in web design. So here we go...
Building a site that will allow the department to manage PTO. I want to implement ajax b/c the main page will have a calendar system so the manager can view the PTO week by week. As a precursor to that, I'm attempting to implement ajax with the "add Employee" page for practice.
However, I can't seem to figure out what I'm missing (aka, why it's not doing anything)
This page just needs to add the new employee to the database. No display needed.
The main page just has 4 text fields and I get the information from those fields in javascript like so
var firstName = document.getElementById("firstNameField");
var lastName = document.getElementById("lastNameField");
var manager = document.getElementById("managerField");
var networkID = document.getElementById("networkIDField");
Simple enough so far.
So I set up the ajax code like so, (this is gathered from what I've read.
var url = "addEmpJSP.jsp?firstNameField=" + escape(firstName)+"&lastNameField="+escape(lastName)+"&managerField="+escape(manager)+"&networkIDField="+escape(networkID);
xmlhttp.open("POST",url,true);
xmlhttp.onreadystatechange=dummy;
xmlhttp.send(null);
This is the part where I'm assuming it's correct as I'm still learning ajax and how it works. I don't think I need to handle a response as I simply want the called jsp file to automatically do whats needed. (if that's possible).
The jsp file looks like this
<%
ResultSet rsEmpl;
Connection connection1 = getDBConnection();
Statement statment1=connection1.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
String fName = request.getParameter("firstNameField");
String lName = request.getParameter("lastNameField");
String manager = request.getParameter("managerField");
String networkID = request.getParameter("networkIDField");
Int empId = 0;
String EditEmplSQL = "select * from PTO_employee";
rsEmpl=statment1.executeQuery(EditEmplSQL);
rsEmpl.last();
empId = rsEmpl.getRow() - 1;
statement1.execute("INSERT INTO PTO_employee VALUES ("+empID+","+lName+","+fName+","+0+","+2+","+networkID);
%>
I have a button on the page that executes the javascript function that contains the ajax info. I'm avoiding jquery atm b/c I'm trying to understand this stuff and how it works before I attempt to use "shortcuts" like jquery. I'm working towards a degree in Software Engineering so understanding this stuff is my priority, not getting it done.(that's just a bonus) If you need anymore information I can provide it. Sorry for my lack of knowledge and if this is completely off base then :(
The main page just has 4 text fields and I get the information from those fields in javascript like so
var firstName = document.getElementById("firstNameField");
var lastName = document.getElementById("lastNameField");
var manager = document.getElementById("managerField");
var networkID = document.getElementById("networkIDField");
That gives you whole HTML DOM elements back, not the values of those elements. HTML DOM elements are like Java classes, having properties, methods and so on. Assuming that it are HTML input elements like <input>, then use their value property instead to get the value. So:
var firstName = document.getElementById("firstNameField").value;
var lastName = document.getElementById("lastNameField").value;
var manager = document.getElementById("managerField").value;
var networkID = document.getElementById("networkIDField").value;
So I set up the ajax code like so, (this is gathered from what I've read.
var url = "addEmpJSP.jsp?firstNameField=" + escape(firstName)+"&lastNameField="+escape(lastName)+"&managerField="+escape(manager)+"&networkIDField="+escape(networkID);
xmlhttp.open("POST",url,true);
xmlhttp.onreadystatechange=dummy;
xmlhttp.send(null);
The escape() is the wrong function. It escapes JS syntax, it does not encode URI components. You should be using encodeURIComponent() function instead.
The jsp file looks like this
...
Int empId = 0;
...
This doesn't compile. It should be int instead.
...
String EditEmplSQL = "select * from PTO_employee";
rsEmpl=statment1.executeQuery(EditEmplSQL);
rsEmpl.last();
empId = rsEmpl.getRow() - 1;
...
Unnecessarily overcomplicated. Learn how to use DB builtin sequences/autoincrement IDs. Refer the DB specific manual or ask DB admin for help.
...
statement1.execute("INSERT INTO PTO_employee VALUES ("+empID+","+lName+","+fName+","+0+","+2+","+networkID);
...
You should put quotes around string values in the SQL query. Assuming that lName, fName and networkID are strings, not numbers, then it should look like this:
statement1.execute("INSERT INTO PTO_employee VALUES (" + empID + ",'" + lName + "','" + fName + "'," + 0 + "," + 2 + ",'" + networkID + "'");
But you have there a huge SQL injection attack hole and you also don't seem to close DB resources at all after use, so they may leak away and cause your webapp to crash sooner or later because the DB runs out of resources. Use PreparedStatement to create a parameterized SQL query and use its setters to set the values. Close the resources in finally block.
After all, reading the server logs should provide you information about compile errors and any server exceptions. Reading the ajax response should provide you information about the response status and body. Your core problem was that you ignored it and thus didn't have any chance to understand what is happening.

Calling a dialog in Dynamics 2011 and passing multiple recordIDs to it

I want to allow the user to select one or many contacts from the contact entity, and then launch a dialog that accepts the record IDs. The idea is to add some custom configuration to the contacts.
I've currently got a custom action on a ribbon button that launches a dialog, but it only accepts one record Id. I can get access to the list of selected record Ids, thatisn't the problem, it is passing a list to the dialog using JavaScript.
I can't seem to find anything in the SDK or code snippets.
The nearest thing I found was this:
http://crmmongrel.blogspot.com/2011/06/launch-dialog-from-ribbon-button-in-crm.html
Anyone know if this is possible? I know the out of the box Send Direct E-Mail allows an email to be sent to the selected items, so I need something similar.
Should I be using dialogs or something else?
Here is a code snippet of the javascript that is called on the click of the ribbon button:
function LaunchModalDialog(SelectedControlSelectedItemReferences,dialogID, typeName)
{
// Get selected objects
var allItems = new Array
var allItems = SelectedControlSelectedItemReferences
// Just get first item for now as dialog only seems to accept one ID
var personId = allItems[0].Id;
personId = personId.replace(/\{/g, "");
personId = personId.replace(/\}/g, "");
// Load modal
var serverUri = Mscrm.CrmUri.create('/cs/dialog/rundialog.aspx');
var mypath = serverUri + '?DialogID={' + dialogID + '}&EntityName=' + typeName + '&ObjectId={' +personId + '}';
mypath = encodeURI(mypath);
// First item from selected contacts only
window.showModalDialog(mypath);
// Reload form.
window.location.reload(true);
}
You'll need to specify the SelectedControlAllItemIds parameter in your Ribbon for that button. Here is a link that describes it:
http://social.microsoft.com/Forums/en/crm/thread/79f959ac-0846-472f-bff1-4f5afe692a56
--Edit--
I'm sorry, I misunderstood - you meant launch an actual CRM Dialog, not just a normal HTML pop-up dialog window.
CRM Dialogs can't be used on multiple records by design, so you aren't going to be able to use them for this.
However, you should be able to create an HTML web resource file that you can launch from the Ribbon, passing in the SelectedControlAllItemIds parameter. That HTML web resource would then have some javascript that would update the selected contacts using the REST endpoints (see the SDK for more information).
Hope that helps!

Categories